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

Tilman Hausherr commented on PDFBOX-6319:
-----------------------------------------

So your patch and my "own" review with Claude Sonnet 5.5 shows two things I 
hadn't thought about, which is overlapping, and reverse ranges. I followed the 
existing code change for W2 and I'll just stay with that to keep the code 
simple except for the reverse range which we should ignore. Tests with my own 
corpus show no difference in text extraction and rendering. (There might be 
surprises with the 250000 files corpus that we do before releases). Differences 
for the average calculations aren't really important because the average is a 
terrible value already, used if we don't know the space width, which happens 
with some math fonts. So what remains is the possibility of having several 
different widths for the same CID, which hasn't happened yet, and if it 
happens, we'll have to investigate which behavior is best.

Claude also found two {{IndexOutOfBoundsException}} possibilities which I'll 
fix separately.

> CIDFont /W range up to Integer.MAX_VALUE causes OutOfMemoryError; /W2 
> non-number entry causes ClassCastException
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-6319
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6319
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 3.0.8 PDFBox, 4.0.0
>            Reporter: Martin Mirchev
>            Assignee: Tilman Hausherr
>            Priority: Major
>         Attachments: PDFBOX-6319-w-ranges.patch, w-range-intmax.pdf, 
> w2-name.pdf
>
>
> Two problems in {{PDCIDFont}} when reading crafted width arrays.
> 1. {{readWidths()}} expands a {{c_first c_last w}} range into one map entry 
> per CID:
> {code:java}
> for (int i = startRange; i <= endRange; i++)
> {
>     widths.put(i, width);
> }
> {code}
> Attached {{w-range-intmax.pdf}} has {{{}/W [0 2147483647 500]{}}}: rendering 
> the page fails with {{OutOfMemoryError}} in 
> {{PDCIDFont.readWidths(PDCIDFont.java:167)}} while the font is created (from 
> {{{}PDResources.getFont{}}}, -Xmx1g). With {{endRange == Integer.MAX_VALUE}} 
> the loop would also never end, because {{i}} wraps. PDFBOX-6175 (on 
> 28.3.2026) stopped expanding {{/W2}} ranges per CID 
> ({{{}VerticalDisplacementRange{}}}); {{/W}} ranges could be kept as ranges in 
> the same way.
> 2. {{readVerticalDisplacements()}} casts {{/W2}} entries to {{COSNumber}} 
> without checks, while {{readWidths()}} logs and skips non-number entries. 
> Attached {{w2-name.pdf}} has {{/W2 [/X [1000 0 0]]}} and rendering fails with 
> {{ClassCastException: COSName cannot be cast to COSNumber}} at 
> {{{}PDCIDFont.readVerticalDisplacements(PDCIDFont.java:195){}}}. PDFBOX-3963 
> fixed an earlier case in the same method.
> Both on trunk bd0c9c0, 3/3 runs; {{/W [0 100 500]}} and a well-formed {{/W2}} 
> load without errors.
> This issue was found by an LLM-assisted tool and verified manually.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to