diff options
author | Mark Thompson <sw@jkqxz.net> | 2018-03-11 14:40:23 +0000 |
---|---|---|
committer | Mark Thompson <sw@jkqxz.net> | 2018-03-18 17:54:55 +0000 |
commit | 0e782661d63b39d729b2167e75a690b4e2934740 (patch) | |
tree | cf25484ebe10d89d5466f8fb497e75160f06665f /libavcodec/cbs_internal.h | |
parent | ce1d77a5e7cebce11074bf6f9e38ad6da37338ff (diff) | |
download | ffmpeg-0e782661d63b39d729b2167e75a690b4e2934740.tar.gz |
cbs_h264: Fix overflow in shifts
The type of the result of a shift operation is unaffected by the type of
the right operand, so some existing code overflows with undefined behaviour
when the element length is 32. Add a helper macro to calculate the maximum
value correctly and then use it everywhere this pattern appears.
Found-by: Andreas Rheinhardt <andreas.rheinhardt@googlemail.com>
Diffstat (limited to 'libavcodec/cbs_internal.h')
-rw-r--r-- | libavcodec/cbs_internal.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h index 5674803472..be540e2a44 100644 --- a/libavcodec/cbs_internal.h +++ b/libavcodec/cbs_internal.h @@ -79,6 +79,10 @@ int ff_cbs_write_unsigned(CodedBitstreamContext *ctx, PutBitContext *pbc, int width, const char *name, uint32_t value, uint32_t range_min, uint32_t range_max); +// The largest value representable in N bits, suitable for use as +// range_max in the above functions. +#define MAX_UINT_BITS(length) ((UINT64_C(1) << (length)) - 1) + extern const CodedBitstreamType ff_cbs_type_h264; extern const CodedBitstreamType ff_cbs_type_h265; |