Skip to content

ROB: Deal with DictionaryObjects having streams of length 0 #3114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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 @@ -647,7 +647,7 @@ def read_unsized_from_stream(
pstart = stream.tell()
if length > 0:
data["__streamdata__"] = stream.read(length)
else:
elif length < 0:
data["__streamdata__"] = read_until_regex(
stream, re.compile(b"endstream")
)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,3 +1219,14 @@ def test_contentstream_arrayobject_containing_nullobject(caplog):
content_stream = ContentStream(stream=input_stream, pdf=None)
assert content_stream.get_data() == b"Hello World!\n"
assert caplog.text == ""


@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>>\nendobj\n" in output.getvalue()
Loading