[FFmpeg-cvslog] bytestream2: set the reader to the end when reading more than available

Anton Khirnov git at videolan.org
Mon Jul 20 10:48:28 CEST 2015


ffmpeg | branch: release/2.6 | Anton Khirnov <anton at khirnov.net> | Fri Jul 10 09:31:24 2015 +0200| [c5c141bc699f9b6f2e5613bc826b0943b70e1011] | committer: Michael Niedermayer

bytestream2: set the reader to the end when reading more than available

This prevents possible infinite loops with the calling code along the
lines of while (bytestream2_get_bytes_left()) { ... }, where the reader
does not advance.

CC: libav-stable at libav.org
(cherry picked from commit 86eee85daddb682fa072c2e2657c90a514b855e3)

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c5c141bc699f9b6f2e5613bc826b0943b70e1011
---

 libavcodec/bytestream.h |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h
index c2cb601..7c05ea6 100644
--- a/libavcodec/bytestream.h
+++ b/libavcodec/bytestream.h
@@ -71,8 +71,10 @@ static av_always_inline type bytestream2_get_ ## name ## u(GetByteContext *g)  \
 }                                                                              \
 static av_always_inline type bytestream2_get_ ## name(GetByteContext *g)       \
 {                                                                              \
-    if (g->buffer_end - g->buffer < bytes)                                     \
+    if (g->buffer_end - g->buffer < bytes) {                                   \
+        g->buffer = g->buffer_end;                                             \
         return 0;                                                              \
+    }                                                                          \
     return bytestream2_get_ ## name ## u(g);                                   \
 }                                                                              \
 static av_always_inline type bytestream2_peek_ ## name(GetByteContext *g)      \



More information about the ffmpeg-cvslog mailing list