Martin Mirchev created PDFBOX-6319:
--------------------------------------

             Summary: 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: 4.0.0, 3.0.8 PDFBox
            Reporter: Martin Mirchev
         Attachments: 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 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