Fix NegativeArraySizeException in PfbParser #412
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NegativeArraySizeException in PfbParser due to Integer Overflow
Summary
PfbParser in Apache PDFBox's fontbox component reads a 4-byte size field as a signed integer without validating for negative values. When processing a malformed PFB font, integer overflow causes a negative size value, leading to
NegativeArraySizeExceptionand application crash.Type: Integer Overflow (CWE-190)
Severity: Medium (CVSS ~5.5)
Impact: Denial of Service (application crash)
Affected Component:
fontbox/src/main/java/org/apache/fontbox/pfb/PfbParser.java:162Root Cause
Vulnerable Code (PfbParser.java:152-162)
When the 4th byte of the size field is >= 0x80, Java's signed integer arithmetic causes overflow to negative. The PDFBOX-6044 bounds check
size > pfb.lengthonly validates the upper bound — negative values pass through and crash at array allocation.PoC
Trigger file
A crafted
malicious_pfb.pdfwith an embedded Type1 font containing an 18-byte PFB payload with size field01 00 00 FFthat overflows to -16777215.How to generate crash.bin
Hex structure (18 bytes):
0x80— Start marker0x01— ASCII segment type01 00 00 FF— Size field (little-endian), overflows to -16777215How to generate malicious_pfb.pdf
Trigger Method 1: Official pdfbox-app CLI
Output:
Note:
NegativeArraySizeExceptionis aRuntimeException, not caught byPDType1Fontwhich only catchesIOExceptionandDamagedFontException.Trigger Method 2: Direct API