decoder/mad: fix integer underflow with very small files

When drop_start_samples and drop_end_samples overlap and are greater
than the actual number of samples, the `num_samples` calculation in
SubmitPCM() could underflow.

Closes https://github.com/MusicPlayerDaemon/MPD/issues/1712
This commit is contained in:
Max Kellermann 2023-01-17 17:38:19 +01:00
parent ad7d47a8ba
commit 15a1973e28
2 changed files with 3 additions and 1 deletions

2
NEWS
View File

@ -1,6 +1,8 @@
ver 0.23.12 (not yet released) ver 0.23.12 (not yet released)
* input * input
- curl: require CURL 7.55.0 or later - curl: require CURL 7.55.0 or later
* decoder
- mad: fix integer underflow with very small files
* tags * tags
- fix crash bug due to race condition - fix crash bug due to race condition
* output * output

View File

@ -843,7 +843,7 @@ MadDecoder::SynthAndSubmit() noexcept
size_t pcm_length = synth.pcm.length; size_t pcm_length = synth.pcm.length;
if (drop_end_samples && if (drop_end_samples &&
current_frame == max_frames - drop_end_frames - 1) { current_frame == max_frames - drop_end_frames - 1) {
if (drop_end_samples >= pcm_length) if (i + drop_end_samples >= pcm_length)
return DecoderCommand::STOP; return DecoderCommand::STOP;
pcm_length -= drop_end_samples; pcm_length -= drop_end_samples;