Skip to content

Commit

Permalink
BUG: Prevent infinite loop when no character follows after a comment (#…
Browse files Browse the repository at this point in the history
…1828)

Fixes #1825
  • Loading branch information
exiledkingcc committed May 21, 2023
1 parent dc6a92e commit b0e5c68
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pypdf/generic/_data_structures.py
Expand Up @@ -1016,7 +1016,7 @@ def __parse_content_stream(self, stream: StreamType) -> None:
# encountering a comment -- but read_object assumes that
# following the comment must be the object we're trying to
# read. In this case, it could be an operator instead.
while peek not in (b"\r", b"\n"):
while peek not in (b"\r", b"\n", b""):
peek = stream.read(1)
else:
operands.append(read_object(stream, None, self.forced_encoding))
Expand Down
3 changes: 3 additions & 0 deletions requirements/ci-3.11.txt
Expand Up @@ -50,10 +50,13 @@ pytest==7.2.2
# -r requirements/ci.in
# pytest-benchmark
# pytest-socket
# pytest-timeout
pytest-benchmark==4.0.0
# via -r requirements/ci.in
pytest-socket==0.6.0
# via -r requirements/ci.in
pytest-timeout==2.1.0
# via -r requirements/ci.in
ruff==0.0.259
# via -r requirements/ci.in
typeguard==3.0.2
Expand Down
1 change: 1 addition & 0 deletions requirements/ci.in
Expand Up @@ -9,6 +9,7 @@ pycryptodome
pytest
pytest-benchmark
pytest-socket
pytest-timeout
typeguard
types-dataclasses
types-Pillow
3 changes: 3 additions & 0 deletions requirements/ci.txt
Expand Up @@ -62,10 +62,13 @@ pytest==7.0.1
# -r requirements/ci.in
# pytest-benchmark
# pytest-socket
# pytest-timeout
pytest-benchmark==3.4.1
# via -r requirements/ci.in
pytest-socket==0.4.1
# via -r requirements/ci.in
pytest-timeout==2.1.0
# via -r requirements/ci.in
six==1.16.0
# via flake8-print
tomli==1.2.3
Expand Down
10 changes: 10 additions & 0 deletions tests/test_reader.py
Expand Up @@ -1401,3 +1401,13 @@ def test_iss1756():
in_pdf = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
in_pdf.trailer["/ID"]
# removed to cope with missing cryptodome during commit check : len(in_pdf.pages)


@pytest.mark.enable_socket()
@pytest.mark.timeout(30)
def test_iss1825():
url = "https://github.com/py-pdf/pypdf/files/11367871/MiFO_LFO_FEIS_NOA_Published.3.pdf"
name = "iss1825.pdf"
reader = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
page = reader.pages[0]
page.extract_text()

0 comments on commit b0e5c68

Please sign in to comment.