Skip to content

FOP-3350: PDFPageLabels: a page label of "0" is written as a prefix label, not read past its end - #122

Open
plutext wants to merge 1 commit into
apache:mainfrom
plutext:FOP-3350
Open

plutext wants to merge 1 commit into
apache:mainfrom
plutext:FOP-3350

Conversation

@plutext

@plutext plutext commented Oct 4, 2026

Copy link
Copy Markdown

Fixes FOP-3350.

PDFPageLabels.addPageLabel counts a decimal label's leading zeros with

do {
    zeroPadding++;
} while (pageLabel.charAt(zeroPadding) == '0');

which runs past the end of a label made only of zeros (StringIndexOutOfBoundsException). A page numbered 0 is
reachable wherever a page sequence's numbering yields 0: an extension, or a user agent that honours
initial-page-number="0", as documents converted from word processors ask for a cover page.

The change. An all-zero decimal label is written as a prefix label (/P), since /St must be at least 1
(ISO 32000-1, 12.4.2), and the loop is skipped for it.

Test. PDFPageLabelsTestCase.testPageNumberedZero labels "0", "1", "2" and expects
[0 << /P (0) >> 1 << /S /D >>]. Without the change it throws. With it, the fop-core suite passes, 3660 tests
and 0 failures, and checkstyle reports 0 violations.

🤖 Generated with Claude Code

…abel, not read past its end

addPageLabel counted a decimal label's leading zeros with a do/while that ran past the end of a
label made only of zeros, throwing StringIndexOutOfBoundsException. Such a label is now written as a
prefix label (/P), since /St must be at least 1 (ISO 32000-1, 12.4.2).

Test: PDFPageLabelsTestCase.testPageNumberedZero, which threw before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant