From 0e782661d63b39d729b2167e75a690b4e2934740 Mon Sep 17 00:00:00 2001 From: Mark Thompson Date: Sun, 11 Mar 2018 14:40:23 +0000 Subject: 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 --- libavcodec/cbs_internal.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libavcodec/cbs_internal.h') 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; -- cgit v1.2.3