leb128: avoid shifts larger than type (#123)

This commit is contained in:
Jacek Sieka 2022-07-16 19:16:11 +02:00 committed by GitHub
parent b55c5a6d74
commit 9a3130eb5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -109,6 +109,11 @@ template read7(shift: untyped) =
if (shift div 7) >= xlen:
return (I(0), 0'i8) # Not enough data - return 0 bytes read
when shift >= sizeof(I) * 8:
# avoid shift overflows: https://github.com/nim-lang/Nim/issues/19983
if true:
return (I(0), -cast[int8]((shift div 7) + 1))
let
b = x[shift div 7]
valb = b and 0x7f'u8 # byte without high bit