Reject invalid WMF unitsPerInch=0 to prevent infinite scaling#1045
Reject invalid WMF unitsPerInch=0 to prevent infinite scaling#1045jmestwa-coder wants to merge 1 commit intoapache:trunkfrom
Conversation
|
@jmestwa-coder can you describe what happens when the new tests are run without the main source change? Maybe the tests could be documented with this detail. |
| unitsPerInch = leis.readShort(); | ||
| unitsPerInch = leis.readUShort(); | ||
| if (unitsPerInch == 0) { | ||
| throw new RecordFormatException("Invalid WMF placeable header unitsPerInch: " + unitsPerInch); |
There was a problem hiding this comment.
add RecordFormatException to the throws clause
There was a problem hiding this comment.
I’ve updated the constructor signature to explicitly declare RecordFormatException for consistency with the parsing code.
93bcea9 to
b892e71
Compare
|
here’s what happens when the new tests are run without this change: When Those values are then used when creating the So without this fix:
With this change:
|
Summary
Reject invalid WMF files where
unitsPerInch = 0to prevent unsafe scaling behavior.Problem
unitsPerInchfrom the placeable WMF header is used as a divisor in scaling calculations.If it is
0, this leads to:This originates from externally supplied WMF input.
Root Cause
unitsPerInchis not validated before being used in scaling.Fix
unitsPerInchas unsigned (readUShort)unitsPerInch == 0at the parser boundary by throwingRecordFormatExceptionWhy This Change
Allowing
unitsPerInch = 0produces infinite dimensions during scaling, which can result in unsafe memory allocation.Rejecting this value prevents undefined and unsafe behavior during WMF processing.
Tests
unitsPerInch = 0→ verifies rejectionTests are deterministic and in-memory.
Compatibility