LibCrypto: Fail with overflow when bitfield has too many unused bits
There cannot be more unused bits than the entirety of the input. Found by OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31706#c1
This commit is contained in:
parent
f9f9cda025
commit
8cc279ed74
Notes:
sideshowbarker
2024-07-18 21:38:14 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/8cc279ed74d Pull-request: https://github.com/SerenityOS/serenity/pull/5692
1 changed files with 6 additions and 1 deletions
|
@ -196,7 +196,12 @@ Result<const BitmapView, DecodeError> Decoder::decode_bit_string(ReadonlyBytes d
|
|||
return DecodeError::InvalidInputFormat;
|
||||
|
||||
auto unused_bits = data[0];
|
||||
return BitmapView { const_cast<u8*>(data.offset_pointer(1)), data.size() * 8 - unused_bits };
|
||||
auto total_size_in_bits = data.size() * 8;
|
||||
|
||||
if (unused_bits > total_size_in_bits)
|
||||
return DecodeError::Overflow;
|
||||
|
||||
return BitmapView { const_cast<u8*>(data.offset_pointer(1)), total_size_in_bits - unused_bits };
|
||||
}
|
||||
|
||||
Result<Tag, DecodeError> Decoder::peek()
|
||||
|
|
Loading…
Add table
Reference in a new issue