After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 573649 - Buffer overflow in gst gstffmpegaudioresample
Buffer overflow in gst gstffmpegaudioresample
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-libav
git master
Other Linux
: Normal critical
: 0.10.7
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2009-03-01 16:54 UTC by Bastiaan Jacques
Modified: 2009-03-06 11:49 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch in report that exposes the bug (555 bytes, patch)
2009-03-01 16:59 UTC, Bastiaan Jacques
none Details | Review
Add a 64bytes padding to the output buffer (662 bytes, patch)
2009-03-06 07:55 UTC, Edward Hervey
committed Details | Review

Description Bastiaan Jacques 2009-03-01 16:54:23 UTC
To reproduce, run: gst-launch neonhttpsrc location=http://www.cs.ucl.ac.uk/teaching/GZ05/samples/tone.wav ! wavparse ! audioconvert ! ffaudioresample ! audio/x-raw-int,rate=44100 ! autoaudiosink

If you run this pipeline using Valgrind, you'll see output like:


==6700== Invalid write of size 2
==6700==    at 0x6D4DEED: audio_resample (in /usr/lib/i686/cmov/libavcodec.so.51.50.0)
==6700==  Address 0x77ebb9e is 2 bytes after a block of size 12,700 alloc'd
==6700==    at 0x4025D2E: malloc (vg_replace_malloc.c:207)
==6700==    by 0x5126B67: g_try_malloc (gmem.c:199)
==6700==    by 0x4ED4DE4: gst_buffer_try_new_and_alloc (in /usr/lib/libgstreamer-0.10.so.0.18.0)

To narrow down the problem, apply this patch, and the assertion will hit when you run the above pipeline:

--- gstffmpegaudioresample.c	2008-11-08 16:45:25.000000000 +0100
+++ ../../../gst-ffmpeg-0.10.6.orig/ext/ffmpeg/gstffmpegaudioresample.c	2009-03-01 17:02:02.000000000 +0100
@@ -281,6 +281,9 @@ gst_ffmpegaudioresample_transform (GstBa
 
   GST_BUFFER_DURATION (outbuf) = gst_util_uint64_scale (ret, GST_SECOND,
       resample->out_rate);
+
+  g_assert(ret * 2 * resample->out_channels <= GST_BUFFER_SIZE(outbuf));
+
   GST_BUFFER_SIZE (outbuf) = ret * 2 * resample->out_channels;
 
   GST_LOG_OBJECT (resample, "Output buffer duration:%" GST_TIME_FORMAT,
Comment 1 Bastiaan Jacques 2009-03-01 16:59:37 UTC
Created attachment 129794 [details] [review]
patch in report that exposes the bug
Comment 2 Bastiaan Jacques 2009-03-01 19:23:33 UTC
Adding a few bytes (I tried 16) to the size returned by gst_ffmpegaudioresample_transform_size() fixes this bug, so I think there is a discrepancy between the way Gstreamer and ffmpeg calculate the output bytes and/or samples.
Comment 3 Edward Hervey 2009-03-05 08:01:17 UTC
I do indeed see the "Invalid write of size 2" when run through valgrind... but it doesn't fail or segfault.

Is it as critical an issue as that ?
Comment 4 Bastiaan Jacques 2009-03-05 13:25:26 UTC
Sometimes it segfaults, sometimes it doesn't. That's the thing with small buffer overflows. I think on OpenBSD it's guaranteed to segfault.

Whether you consider a "sometimes segfault" a critical issue or not I leave to you.
Comment 5 Edward Hervey 2009-03-06 07:44:39 UTC
Definitely critical then. Will cook up a patch.
Comment 6 Edward Hervey 2009-03-06 07:55:36 UTC
Created attachment 130185 [details] [review]
Add a 64bytes padding to the output buffer

This patch adds 64 bytes to the output buffer used by the resampling function.

I noticed at the same time that we might want to switch to av_resample* (as opposed to audio_resample*).
Comment 7 Edward Hervey 2009-03-06 11:49:54 UTC
commit df6fb6867ed19bfc5f735518452153d5e81efc04
Author: Edward Hervey <bilboed@bilboed.com>
Date:   Fri Mar 6 12:47:12 2009 +0100

    ffaudioresample: Add padding to output buffer. Fixes #573649
    
    The internal resampling functions seem to require a slightly bigger buffer
    for output than what we require. Therefore we give it an extra 64bytes (although
    16 should have been enough).