From 41b2d37e8a8c8efb5a02dbdb373e1f798420e137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Fri, 8 Jul 2022 23:27:24 +0200 Subject: [PATCH] AK: Always check shift amount in LEB128 read functions Even shifting 0 by more than the value size is UB. --- AK/LEB128.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AK/LEB128.h b/AK/LEB128.h index 69b48576bc0..ff5b46b6b98 100644 --- a/AK/LEB128.h +++ b/AK/LEB128.h @@ -36,7 +36,7 @@ struct LEB128 { return false; ValueType masked_byte = byte & ~(1 << 7); - bool const shift_too_large_for_result = (num_bytes * 7 > sizeof(ValueType) * 8) && (masked_byte != 0); + bool const shift_too_large_for_result = num_bytes * 7 > sizeof(ValueType) * 8; if (shift_too_large_for_result) return false; @@ -83,7 +83,7 @@ struct LEB128 { // note: 64 bit assumptions! u64 masked_byte = byte & ~(1 << 7); - bool const shift_too_large_for_result = (num_bytes * 7 >= 64) && (masked_byte != ((temp < 0) ? 0x7Fu : 0u)); + bool const shift_too_large_for_result = num_bytes * 7 >= 64; if (shift_too_large_for_result) return false;