[
https://issues.apache.org/jira/browse/PDFBOX-6369?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18155159#comment-18155159
]
ASF subversion and git services commented on PDFBOX-6369:
---------------------------------------------------------
Commit 1941249 from Maruan Sahyoun in branch 'pdfbox/branches/3.0'
[ https://svn.apache.org/r1941249 ]
PDFBOX-6369: Avoid excessive memory use when reading GSUB tables
Co-Authored-By: Claude <[email protected]>
> Avoid excessive memory use when reading GSUB tables
> ---------------------------------------------------
>
> Key: PDFBOX-6369
> URL: https://issues.apache.org/jira/browse/PDFBOX-6369
> Project: PDFBox
> Issue Type: Bug
> Affects Versions: 2.0.37, 3.0.8 PDFBox, 4.0.0
> Reporter: Maruan Sahyoun
> Assignee: Maruan Sahyoun
> Priority: Major
> Fix For: 2.0.38, 3.0.9 PDFBox, 4.0.0
>
>
> Reading the GSUB table of a TrueType or OpenType font can take far more
> memory than the size of the table. A format 2 coverage table is expanded into
> one boxed `Integer` per glyph, so that each 6-byte range record can result in
> up to 65536 objects. Subtables referenced several times through their offsets
> are read again for each reference. In addition, the `GsubData` used for
> writing text is built eagerly when the font is parsed, with a complete copy
> of the substitutions for each feature tag, although fonts loaded from a PDF
> never use it. A GSUB table of less than 1 KB with 100 feature tags sharing
> one lookup retains about 850 MB, and a table of a few KB causes an
> `OutOfMemoryError` while a document with such an embedded font is being
> opened.
> Found by a Claude security scan.
> Proposed change
> - Build the `GsubData` on the first call of `getGsubData()` instead of when
> the table is read.
> - Limit the substitution entries in the `GsubData` to 65536 or 8 times the
> table size, whichever is larger; if the limit is reached, skip the remaining
> entries and log a warning.
> - Keep the range records of format 2 coverage tables and look up glyphs by
> binary search instead of expanding them.
> - Limit the entries created while reading a GSUB table in proportion to the
> table size; if the limit is exceeded, log a warning and treat the table as
> empty.
> - Add regression tests for coverage tables with many ranges, for many
> feature tags and for shared subtables.
> Claude on behalf of Maruan Sahyoun (msahyoun)
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]