Skip to content

Commit

Permalink
Fix EOF reads on streams with an unknown size (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper authored Oct 18, 2023
1 parent 3b865b7 commit 6704c0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dissect/util/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ def read(self, n: int = -1) -> bytes:
if self._buf:
buffer_pos = self._pos - self._pos_align
r.append(self._buf[buffer_pos:])
self._set_pos(self._pos_align + align)

r.append(self._read(self._pos_align + align, -1))
r.append(self._read(self._pos_align, -1))

buf = b"".join(r)
self._set_pos(self._pos + len(buf))
Expand Down
4 changes: 4 additions & 0 deletions tests/test_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def test_relative_stream():
assert fh.read(15) == b"\x02" * 5 + b"\x03" * 10
assert fh.read(1) == b""

fh.seek(0)
fh._buf = None
assert fh.read() == b"\x01" * 5 + b"\x02" * 10 + b"\x03" * 10


def test_buffered_stream():
buf = io.BytesIO(b"\x01" * 512 + b"\x02" * 512 + b"\x03" * 512)
Expand Down

0 comments on commit 6704c0d

Please sign in to comment.