Skip to content
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

BUG: cope with encoding with too many differences #2873

Merged
merged 1 commit into from
Sep 26, 2024
Merged
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
3 changes: 2 additions & 1 deletion pypdf/_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ def parse_encoding(
x = o
else: # isinstance(o,str):
try:
encoding[x] = adobe_glyphs[o] # type: ignore
if x < len(encoding):
encoding[x] = adobe_glyphs[o] # type: ignore
except Exception:
encoding[x] = o # type: ignore
if o == " ":
Expand Down
11 changes: 11 additions & 0 deletions tests/test_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,14 @@ def test_unigb_utf16():
name = "iss2812.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
assert "《中国能源展望 2060(2024 年版)》编写委员会" in reader.pages[1].extract_text()


@pytest.mark.enable_socket()
def test_too_many_differences():
"""Cf #2836"""
url = (
"https://github.com/user-attachments/files/16911741/dumb_extract_text_crash.pdf"
)
name = "iss2836.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
assert reader.pages[0].extract_text() == ""
Loading