diff options
author | Tim Schumacher <timschumi@gmx.de> | 2023-04-27 11:33:08 +0200 |
---|---|---|
committer | Jelle Raaijmakers <jelle@gmta.nl> | 2023-05-04 20:01:16 +0200 |
commit | 56d861ebe0353df4b3a12a51dc1f103e12292f34 (patch) | |
tree | 57b6f1f5b76f75787a98c6bd32e7c799c7479a25 /AK | |
parent | dffef6bb71bf1012868ad0cd80fbe671375d265c (diff) | |
download | serenity-56d861ebe0353df4b3a12a51dc1f103e12292f34.zip |
AK: Prevent bit counter underflows in the new BitStream
Our current `peek_bits` function allows retrieving more bits than we can
actually provide, so whenever someone discards the requested bit count
afterwards we were underflowing the value instead.
Diffstat (limited to 'AK')
-rw-r--r-- | AK/BitStream.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/AK/BitStream.h b/AK/BitStream.h index 3ddca57267..c03ac22ada 100644 --- a/AK/BitStream.h +++ b/AK/BitStream.h @@ -222,6 +222,10 @@ public: ALWAYS_INLINE void discard_previously_peeked_bits(u8 count) { + // We allow "retrieving" more bits than we can provide, but we need to make sure that we don't underflow the current bit counter. + if (count > m_bit_count) + count = m_bit_count; + m_bit_offset += count; m_bit_count -= count; } |