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

fixing #2548 #2718

Merged
merged 1 commit into from
Oct 6, 2023
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
8 changes: 4 additions & 4 deletions src/extra.i
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ static pdf_obj *lll_JM_pdf_obj_from_str(fz_context *ctx, pdf_document *doc, cons
}

fz_catch(ctx) {
fz_rethrow(ctx);
mupdf::internal_throw_exception(ctx);
}

return result;
Expand Down Expand Up @@ -3744,7 +3744,7 @@ fz_stext_page* page_get_textpage(
fz_drop_device(ctx, dev);
}
fz_catch(ctx) {
return NULL;
mupdf::internal_throw_exception(ctx);
}
return tpage;
}
Expand Down Expand Up @@ -3965,7 +3965,7 @@ JM_new_buffer_from_stext_page(fz_stext_page *page)
}
fz_catch(ctx) {
fz_drop_buffer(ctx, buf);
fz_rethrow(ctx);
mupdf::internal_throw_exception(ctx);
}
return buf;
}
Expand Down Expand Up @@ -4209,7 +4209,7 @@ no_more_matches:;
fz_always(ctx)
fz_drop_buffer(ctx, buffer);
fz_catch(ctx)
fz_rethrow(ctx);
mupdf::internal_throw_exception(ctx);

return quads;
}
Expand Down
Binary file added tests/resources/test_2548.pdf
Binary file not shown.
27 changes: 27 additions & 0 deletions tests/test_2548.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os

import fitz

root = os.path.abspath(f'{__file__}/../..')

def test_2548():
"""Text extraction should fail because of PDF structure cycle.

Old MuPDF version did not detect the loop.
"""
doc = fitz.open(f'{root}/tests/resources/test_2548.pdf')
e = False
for page in doc:
try:
_ = page.get_text()
except Exception as ee:
print(f'test_2548: {ee=}')
if hasattr(fitz, 'mupdf'):
# Rebased.
expected = "RuntimeError('code=2: cycle in structure tree')"
else:
# Classic.
expected = "RuntimeError('cycle in structure tree')"
assert repr(ee) == expected, f'Expected {expected=} but got {repr(ee)=}.'
e = True
assert e