Skip to content

Fix #1163: throw DocumentException instead of writing 'ERROR: Infinite table loop' into the PDF - #1596

Open
andreasrosdalw wants to merge 1 commit into
LibrePDF:masterfrom
andreasrosdalw:fix-1163-infinite-table-loop
Open

Fix #1163: throw DocumentException instead of writing 'ERROR: Infinite table loop' into the PDF#1596
andreasrosdalw wants to merge 1 commit into
LibrePDF:masterfrom
andreasrosdalw:fix-1163-infinite-table-loop

Conversation

@andreasrosdalw

@andreasrosdalw andreasrosdalw commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1163.

When a PdfPTable row can never fit on a page — typically a cell with a fixed height larger than the page height, as in the issue's reproduction — the layout loop in PdfDocument.addPTable gave up after three attempts and silently wrote the literal text ERROR: Infinite table loop into the generated document. The caller received a corrupted PDF and no signal that anything went wrong; the reporter only discovered the text on the last page of the output.

Fix

Throw a DocumentException with a descriptive, localized message instead:

Could not add the table to the document: a table row does not fit on a page. Check for rows or cells whose (fixed) height is larger than the available page height.

This surfaces the error through the normal Document.add(...) error channel (which already declares DocumentException), so callers can catch it and fix their layout, rather than shipping a broken document.

Note on behavior: code that previously "succeeded" while producing a PDF containing the error text will now get an exception. That is the intent — the old behavior corrupted the output silently.

Tests

New TableRowTooTallTest:

  • rowTallerThanPageThrowsInsteadOfWritingErrorText — a one-cell table with fixedHeight = pageHeight + 100 now throws DocumentException (previously: silently produced a PDF containing the error text). Guarded by a preemptive timeout so a regression to a genuine infinite loop fails fast.
  • fittingTableIsUnaffected — normal tables still render, with no error text in the extracted output.

Full openpdf-core suite passes (the existing TableEndlessTest scenarios are unaffected).

… Infinite table loop' into the PDF

When a PdfPTable row can never fit on a page (e.g. a cell with a fixed
height larger than the page height), the layout loop in
PdfDocument.addPTable gave up after three attempts and silently added
the literal text 'ERROR: Infinite table loop' to the generated
document. Callers got a corrupted PDF and no signal that anything went
wrong.

Throw a DocumentException with a descriptive, localized message instead
so the error surfaces through the normal Document.add error channel.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 2 duplication

Metric Results
Complexity 0
Duplication 2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@sonarqubecloud

Copy link
Copy Markdown

@rigopoui

rigopoui commented Jul 23, 2026

Copy link
Copy Markdown

To add to this. I was just getting a pdf conformance error due to a non-embedded font (Helvetica, which is the default).

After being baffled, and looking into the bug (took some time), I discovered that the problem was this "ERROR: Infinite table loop" text being inserted. This was causing the conformance error. When in truth, the actual problem was with an image not being scaled correctly and not fitting in a table 😵‍💫

Having an error for this would be much better, and save people some time (not being paranoid about their font usage)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] ERROR: Infinite table loop

2 participants