Skip to content

Commit

Permalink
return None on invalid data len instead of IndexError
Browse files Browse the repository at this point in the history
  • Loading branch information
malwarefrank committed Apr 3, 2024
1 parent b844590 commit fcccdaf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/dnfile/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def read_compressed_int(data) -> Optional[Tuple[int, int]]:
if data[0] & 0x80 == 0:
# values 0x00 to 0x7f
return data[0], 1
elif data[0] & 0x40 == 0:
elif len(data) >= 2 and data[0] & 0x40 == 0:
# values 0x80 to 0x3fff
value = (data[0] & 0x7F) << 8
value |= data[1]
return value, 2
elif data[0] & 0x20 == 0:
elif len(data) >= 4 and data[0] & 0x20 == 0:
# values 0x4000 to 0x1fffffff
value = (data[0] & 0x3F) << 24
value |= data[1] << 16
Expand Down

0 comments on commit fcccdaf

Please sign in to comment.