From: Andre Noll Date: Tue, 3 Sep 2013 22:13:41 +0000 (+0000) Subject: flacdec: Fix mono output. X-Git-Tag: v0.5.1~4^2~2 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=a1beef4331994ddeb9fe0fd9fee363bfb91875e7;p=paraslash.git flacdec: Fix mono output. In the write callback of the flac decoder we correctly allocate and fill an output buffer of n * 2 bytes for mono streams, where n is the block size stored in the frame header. However, later in this function twice as many bytes are added to the buffer tree. This may result in a segmentation fault due to reading beyond the allocated buffer. Fix this by adding n * channels * 2 bytes, which is correct for both mono and stereo files. --- diff --git a/flacdec_filter.c b/flacdec_filter.c index 4220b5d6..b51ac3bd 100644 --- a/flacdec_filter.c +++ b/flacdec_filter.c @@ -144,7 +144,7 @@ static FLAC__StreamDecoderWriteStatus write_cb( write_int16_host_endian(outbuffer + 4 * k + 2, right); } } - btr_add_output(outbuffer, n * 4, btrn); + btr_add_output(outbuffer, n * channels * 2, btrn); flac_consume(fn); return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; }