From: Martin Storsjö Date: Sat, 26 Feb 2011 23:02:32 +0000 (+0200) Subject: aviobuf: Write new data at s->buf_end in fill_buffer X-Git-Tag: android-x86-4.4-r1~18264 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=62d0a7453af12e9e7880dd08d4dafe20374625c1;p=android-x86%2Fexternal-ffmpeg.git aviobuf: Write new data at s->buf_end in fill_buffer In most cases, s->buf_ptr will be equal to s->buf_end when fill_buffer is called, but this may not always be the case, if we're seeking forward by reading (permitted by the short seek threshold). If fill_buffer is writing to s->buf_ptr instead of s->buf_end (when they aren't equal and s->buf_ptr is ahead of s->buffer), the data between s->buf_ptr and s->buf_end is overwritten, leading to inconsistent buffer content. This could return incorrect data if later seeking back into the area before the current s->buf_ptr. Signed-off-by: Luca Barbato (cherry picked from commit e360ada2d13af36ab7afd9ebcd2bd236d23d9b96) --- diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 0c733a704b..3f3721c58b 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -468,7 +468,7 @@ void put_tag(AVIOContext *s, const char *tag) static void fill_buffer(AVIOContext *s) { - uint8_t *dst= !s->max_packet_size && s->buf_end - s->buffer < s->buffer_size ? s->buf_ptr : s->buffer; + uint8_t *dst= !s->max_packet_size && s->buf_end - s->buffer < s->buffer_size ? s->buf_end : s->buffer; int len= s->buffer_size - (dst - s->buffer); int max_buffer_size = s->max_packet_size ? s->max_packet_size : IO_BUFFER_SIZE;