Skip to content

Commit

Permalink
Fix read_sid for empty buffers (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
JSCU-CNI authored Jan 14, 2025
1 parent 2a9439e commit 166f63e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dissect/util/sid.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def read_sid(fh: BinaryIO | bytes, endian: str = "<", swap_last: bool = False) -
if isinstance(fh, bytes):
fh = io.BytesIO(fh)

buf = fh.read(8)
if len(buf := fh.read(8)) != 8:
return ""

revision = buf[0]
sub_authority_count = buf[1]
authority = int.from_bytes(buf[2:], "big")
Expand Down
12 changes: 12 additions & 0 deletions tests/test_sid.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ def id_fn(val: bytes | str) -> str:
if isinstance(val, str):
return val

if val == b"":
return "empty-value"

if isinstance(val, bytes):
return val.hex()

if val is None:
return "None"

return ""


Expand Down Expand Up @@ -66,6 +72,12 @@ def id_fn(val: bytes | str) -> str:
">",
True,
),
(
b"",
"",
"<",
False,
),
],
ids=id_fn,
)
Expand Down

0 comments on commit 166f63e

Please sign in to comment.