Skip to content

Commit

Permalink
ROB: Replace error by warning for EOD in RunLengthDecode/ASCIIHexDeco…
Browse files Browse the repository at this point in the history
…de (#2334)

Fixes #2303.
  • Loading branch information
pubpub-zz authored Mar 30, 2024
1 parent e35df5a commit 42f970e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
6 changes: 4 additions & 2 deletions pypdf/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ def decode(
index = 0
while True:
if index >= len(data):
raise PdfStreamError("Unexpected EOD in ASCIIHexDecode")
logger_warning("missing EOD in ASCIIHexDecode, check if output is OK", __name__)
break # reach End Of String even if no EOD
char = data[index : index + 1]
if char == b">":
break
Expand Down Expand Up @@ -340,7 +341,8 @@ def decode(
index = 0
while True:
if index >= len(data):
raise PdfStreamError("Unexpected EOD in RunLengthDecode")
logger_warning("missing EOD in RunLengthDecode, check if output is OK", __name__)
break # reach End Of String even if no EOD
length = data[index]
index += 1
if length == 128:
Expand Down
16 changes: 6 additions & 10 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from PIL import Image

from pypdf import PdfReader
from pypdf.errors import DeprecationError, PdfReadError, PdfStreamError
from pypdf.errors import DeprecationError, PdfReadError
from pypdf.filters import (
ASCII85Decode,
ASCIIHexDecode,
Expand Down Expand Up @@ -131,9 +131,9 @@ def test_ascii_hex_decode_method(data, expected):

def test_ascii_hex_decode_missing_eod():
"""ASCIIHexDecode.decode() raises error when no EOD character is present."""
with pytest.raises(PdfStreamError) as exc:
ASCIIHexDecode.decode("")
assert exc.value.args[0] == "Unexpected EOD in ASCIIHexDecode"
# with pytest.raises(PdfStreamError) as exc:
ASCIIHexDecode.decode("")
# assert exc.value.args[0] == "Unexpected EOD in ASCIIHexDecode"


@pytest.mark.enable_socket()
Expand Down Expand Up @@ -500,14 +500,10 @@ def test_runlengthdecode():
url = "https://github.com/py-pdf/pypdf/files/12162905/out.pdf"
name = "FailedRLE1.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
with pytest.raises(PdfStreamError) as exc:
reader.pages[0].images[0]
assert exc.value.args[0] == "Unexpected EOD in RunLengthDecode"
reader.pages[0].images[0]
url = "https://github.com/py-pdf/pypdf/files/12162926/out.pdf"
name = "FailedRLE2.pdf"
with pytest.raises(PdfStreamError) as exc:
reader.pages[0].images[0]
assert exc.value.args[0] == "Unexpected EOD in RunLengthDecode"
reader.pages[0].images[0]


@pytest.mark.enable_socket()
Expand Down

0 comments on commit 42f970e

Please sign in to comment.