[FFmpeg-devel] [PATCH 02/15] bytestream: Make get_bytes_left compatible with overread

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Thu Oct 17 11:29:32 EEST 2019


bytestream2_get_bytes_left returns an unsigned int; as a result,
it returns big positive numbers if an overread already happened,
making it unsuitable for scenarios where one wants to allow this
(because the buffer is actually padded so that no segfaults can
happen). So add a function returning ptrdiff_t for this purpose;
given that it is intended to be used with the unsafe functions,
it has an "u" suffix, although it is not unsafe by itself.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavcodec/bytestream.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h
index 7be7fc22fc..18774524cf 100644
--- a/libavcodec/bytestream.h
+++ b/libavcodec/bytestream.h
@@ -156,6 +156,11 @@ static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *
     return g->buffer_end - g->buffer;
 }
 
+static av_always_inline ptrdiff_t bytestream2_get_bytes_leftu(GetByteContext *g)
+{
+    return g->buffer_end - g->buffer;
+}
+
 static av_always_inline unsigned int bytestream2_get_bytes_left_p(PutByteContext *p)
 {
     return p->buffer_end - p->buffer;
-- 
2.20.1



More information about the ffmpeg-devel mailing list