From fcccdafb00c37b4e47c038b4dd855408c69f2ece Mon Sep 17 00:00:00 2001 From: malwarefrank <42877127+malwarefrank@users.noreply.github.com> Date: Wed, 3 Apr 2024 23:04:59 +0000 Subject: [PATCH] return None on invalid data len instead of IndexError --- src/dnfile/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dnfile/utils.py b/src/dnfile/utils.py index 90232bf..35e913b 100644 --- a/src/dnfile/utils.py +++ b/src/dnfile/utils.py @@ -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