From 657ee2da596a783b6df1c5d056bf982435ed39e8 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Thu, 20 Oct 2011 20:47:53 +0200 Subject: COMMON: Fix potential UB while shifting Common::BitStream Shifting a 32-bit value by more than 31 is undefined. --- common/bitstream.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'common') diff --git a/common/bitstream.h b/common/bitstream.h index 34063dbfe1..61ec4abc76 100644 --- a/common/bitstream.h +++ b/common/bitstream.h @@ -176,6 +176,9 @@ public: /** Read a multi-bit value from the bit stream. */ uint32 getBits(uint8 n) { + if (n == 0) + return 0; + if (n > 32) error("BitStreamImpl::getBits(): Too many bits requested to be read"); @@ -225,6 +228,9 @@ public: /** Add a bit to the value x, making it an n-bit value. */ void addBit(uint32 &x, uint32 n) { + if (n >= 32) + error("BitStreamImpl::addBit(): Too many bits requested to be read"); + if (isMSB2LSB) x = (x << 1) | getBit(); else -- cgit v1.2.3