aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuca Barbato <lu_zero@gentoo.org>2013-01-13 23:37:11 +0100
committerLuca Barbato <lu_zero@gentoo.org>2013-01-14 05:22:22 +0100
commit71e00caeab89d9beeef9c947673f72e992bd109c (patch)
tree60a0780eeb04460b4d57936c983d0c2c188e6206
parent7a2ee770f520ae4fd5f009cfc361a18e993dec91 (diff)
downloadffmpeg-71e00caeab89d9beeef9c947673f72e992bd109c.tar.gz
lavc: introduce the convenience function init_get_bits8
Accept the buffer size in bytes and check for overflow before passing the value in bits to init_get_bits. (cherry picked from commit e28ac6e5e27e64a206e399e958481c1e6f992189) Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
-rw-r--r--libavcodec/get_bits.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h
index 16cfd5e0fd..12770a29a0 100644
--- a/libavcodec/get_bits.h
+++ b/libavcodec/get_bits.h
@@ -393,6 +393,22 @@ static inline int init_get_bits(GetBitContext *s, const uint8_t *buffer,
return ret;
}
+/**
+ * Initialize GetBitContext.
+ * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes
+ * larger than the actual read bits because some optimized bitstream
+ * readers read 32 or 64 bit at once and could read over the end
+ * @param byte_size the size of the buffer in bytes
+ * @return 0 on success, AVERROR_INVALIDDATA if the buffer_size would overflow.
+ */
+static inline int init_get_bits8(GetBitContext *s, const uint8_t *buffer,
+ int byte_size)
+{
+ if (byte_size > INT_MAX / 8)
+ return AVERROR_INVALIDDATA;
+ return init_get_bits(s, buffer, byte_size * 8);
+}
+
static inline void align_get_bits(GetBitContext *s)
{
int n = -get_bits_count(s) & 7;