[FFmpeg-devel] Patch for seg fault in swr_convert_internal() -> sum2_float during dithering

Hendrik Schreiber hs at tagtraum.com
Thu Apr 5 15:38:03 EEST 2018

Hey there,

I have recently switched to using FFmpeg for conversions of 24bit stereo WAV to 16bit stereo WAV (with dithering).

For some very large files, I occasionally encountered a segmentation fault in _sum2_float. Unfortunately, I was not able to reproduce the issue in a small test setting, but only in a quite large environment.

Debugging showed that the issue was caused in function swr_convert_internal() in swresample.c, specifically in line 681

conv_src->ch[ch] + off, // out array
preout->ch[ch] + off,   // in1 array
s->dither.noise.ch[ch] + s->dither.noise.bps * s->dither.noise_pos + off + len1, // in2 array
s->native_one,          // coefficients
0,                      // coefficient index 1
0,                      // coefficient index 2
out_count - len1        // length


where dithering is applied. Here, s->mix_2_1_f() is the same as sum2_float(). The in2 array pointer is too large.

I was able to log values before one of the crashs and found:

(out_count - len1)=10
s->dither.noise.bps  =4
s->dither.noise_pos  =130262
s->dither.noise.bps * s->dither.noise_pos + off + len1 = 524408 // in2 start address offset greater than buffer size!!!

The buffer count has a total size of s->dither.noise.count * s->dither.noise.bps = 524288
Therefore the start address for the in2 array (3rd argument for mix_2_1_f(...)) is already outside of the buffer.

I was not able to find a reason for the “+len1” in “s->dither.noise.bps * s->dither.noise_pos + off + len1”. It looks out of place to me. Without it the buffer overrun does not occur.

“make fate” worked like a charm.


tagtraum industries incorporated
724 Nash Drive
Raleigh, NC 27608
+1 (919) 809-7797

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: h_schreiber_mix_2_1_f_seg_fault_patch.txt
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180405/b990edb6/attachment.txt>
-------------- next part --------------

More information about the ffmpeg-devel mailing list