Skip to content

Commit 42f970e

Browse files
authored
ROB: Replace error by warning for EOD in RunLengthDecode/ASCIIHexDecode (#2334)
Fixes #2303.
1 parent e35df5a commit 42f970e

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

pypdf/filters.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ def decode(
285285
index = 0
286286
while True:
287287
if index >= len(data):
288-
raise PdfStreamError("Unexpected EOD in ASCIIHexDecode")
288+
logger_warning("missing EOD in ASCIIHexDecode, check if output is OK", __name__)
289+
break # reach End Of String even if no EOD
289290
char = data[index : index + 1]
290291
if char == b">":
291292
break
@@ -340,7 +341,8 @@ def decode(
340341
index = 0
341342
while True:
342343
if index >= len(data):
343-
raise PdfStreamError("Unexpected EOD in RunLengthDecode")
344+
logger_warning("missing EOD in RunLengthDecode, check if output is OK", __name__)
345+
break # reach End Of String even if no EOD
344346
length = data[index]
345347
index += 1
346348
if length == 128:

tests/test_filters.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from PIL import Image
1212

1313
from pypdf import PdfReader
14-
from pypdf.errors import DeprecationError, PdfReadError, PdfStreamError
14+
from pypdf.errors import DeprecationError, PdfReadError
1515
from pypdf.filters import (
1616
ASCII85Decode,
1717
ASCIIHexDecode,
@@ -131,9 +131,9 @@ def test_ascii_hex_decode_method(data, expected):
131131

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

138138

139139
@pytest.mark.enable_socket()
@@ -500,14 +500,10 @@ def test_runlengthdecode():
500500
url = "https://github.com/py-pdf/pypdf/files/12162905/out.pdf"
501501
name = "FailedRLE1.pdf"
502502
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
503-
with pytest.raises(PdfStreamError) as exc:
504-
reader.pages[0].images[0]
505-
assert exc.value.args[0] == "Unexpected EOD in RunLengthDecode"
503+
reader.pages[0].images[0]
506504
url = "https://github.com/py-pdf/pypdf/files/12162926/out.pdf"
507505
name = "FailedRLE2.pdf"
508-
with pytest.raises(PdfStreamError) as exc:
509-
reader.pages[0].images[0]
510-
assert exc.value.args[0] == "Unexpected EOD in RunLengthDecode"
506+
reader.pages[0].images[0]
511507

512508

513509
@pytest.mark.enable_socket()

0 commit comments

Comments
 (0)