Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pypdf/generic/_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def read_unsized_from_stream(
if length is None: # if the PDF is damaged
length = -1
pstart = stream.tell()
if length > 0:
if length >= 0:
data["__streamdata__"] = stream.read(length)
else:
data["__streamdata__"] = read_until_regex(
Expand Down
11 changes: 11 additions & 0 deletions tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,3 +1265,14 @@ def test_build_link__go_to_action_without_destination():
for page in reader.pages:
writer.add_page(page)
assert len(writer.pages) == len(reader.pages)


@pytest.mark.enable_socket
def test_dictionaryobject__length_0_stream():
"""Test for issue #3052."""
url = "https://github.com/user-attachments/files/18734105/correct.pdf"
name = "issue3052.pdf"
writer = PdfWriter(clone_from=BytesIO(get_data_from_url(url, name=name)))
output = BytesIO()
writer.write(output)
assert b"\n8 0 obj\n<<\n/Length 0\n>>\nstream\n\nendstream\nendobj\n" in output.getvalue()
Loading