[ 
https://issues.apache.org/jira/browse/FOP-3350?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18124630#comment-18124630
 ] 

Jason Harrop commented on FOP-3350:
-----------------------------------

No, and the description should have said so: no FO reaches it in stock FOP. The 
only XSL route to a page numbered 0 is initial-page-number="0", and FOP's error 
recovery makes that 1. I checked on main at 5be8c69b6: with that attribute 
fo:page-number prints 1 and the page label is /S /D from 1.
The path is reached by an embedder. docx4j-fo-renderer, a modified distribution 
derived from FOP that docx4j uses for its PDF output, honours 
initial-page-number="0" as an opt-in, because documents converted from word 
processors number a cover page 0, and that is where addPageLabel threw. The 
unit test in the pull request is the reproduction: 
PDFPageLabelsTestCase.testPageNumberedZero calls addPageLabel(0, "0"), which 
throws StringIndexOutOfBoundsException without the fix.
So this is a one-line hardening of a public class against an input FOP itself 
does not produce. If you would rather not take it for that reason, closing is 
reasonable; the fork carries it either way.

> PDFPageLabels.addPageLabel throws StringIndexOutOfBoundsException for a page 
> label of "0"
> -----------------------------------------------------------------------------------------
>
>                 Key: FOP-3350
>                 URL: https://issues.apache.org/jira/browse/FOP-3350
>             Project: FOP
>          Issue Type: Bug
>          Components: renderer/pdf
>    Affects Versions: 2.11, main
>            Reporter: Jason Harrop
>            Priority: Major
>
> addPageLabel counts a decimal label's leading zeros with
> {code:java}
> do {
>     zeroPadding++;
> } while (pageLabel.charAt(zeroPadding) == '0');
> {code}
> which runs past the end of a label made only of zeros. 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.
> h3. Fix
> Write an all-zero decimal label as a prefix label (/P), since /St must be at 
> least 1 (ISO 32000-1, 12.4.2), and so skip the loop for it. Test: 
> PDFPageLabelsTestCase.testPageNumberedZero labels "0", "1", "2" as {{\[0 << 
> /P (0) >> 1 << /S /D >>\]}}; without the fix it throws.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to