Details
Description
We experienced an OutOfMemoryError when calling
PDAcroForm.getDefaultResources().getFont(COSName); with COSName{Helv}
The reason seemed to be that PdfBox initializes a FontCache when getFont is called and this scans all fonts on the system. This also loads some large system fonts (AppleColorEmoji is 189,9MB). Each font gets copied into a single large byte array at the location below and this causes an OutOfMemoryError at this point in the code.
org.apache.pdfbox.pdmodel.font.FileSystemFontProvider#addTrueTypeFontImpl:773
InputStream is = ttf.getOriginalData(); byte[] ba = IOUtils.toByteArray(is); is.close(); String hash = computeHash(ba);
I think this would be easily fixed by using a DigestInputStream instead of a byte array to compute hashes at this location. I have tested this locally and it seemed to work. Please see the attached .patch file