pjfanning opened a new pull request, #1559:
URL: https://github.com/apache/poi/pull/1559
Part of #1556 (group B), follow-up to #1557.
These asserts checked values that the EMF, EMF+ and WMF specs say MUST or
SHOULD have, but parsing carries on fine without them. With `-ea` they rejected
files that are otherwise readable. They now log a warning instead, as
`HemfFill` and `HemfPlusMisc` already do for the same kind of check:
- `HemfPalette`: palette version 0x0300
- `HemfPlusDraw`: pen id 0-63 and data size 4 in DrawPath; source unit Pixel
in DrawImage and DrawImagePoints; point count 3 in DrawImagePoints. A missing
pen still fails when drawing, with the existing `NoSuchElementException` from
the object table.
- `HemfComment`: the comment identifier and the record type of nested
comments
- `HemfDraw`: the point types after PT_BEZIERTO
- `HemfMisc`: style entries on a pen without user style
- `HemfEmbeddedIterator`: the CONTINUED type of continued image chunks
- `HwmfFill`: the op code of a raster operation
Three of these asserts hid real problems:
- **`HemfPlusImage`:** for an image of unknown type, `fileSize` was the
whole data size although the version and type had already been read, so the
image data ran 8 bytes into the next record. It's now `dataSize - size`, like
the other image types, and the assert always holds, so it's gone.
- **`HemfPlusRecordIterator`:** a record that reads past its size went on to
`skipFully` with a negative count. It now throws `RecordFormatException("Record
limit exceeded ...")`, the same message `HemfRecordIterator` uses.
- **`HwmfBitmapDib`:** the check for a `BitmapCoreHeader` compared the
computed size with `headerImageSize`, which that header doesn't have (it stays
-1), so the check could never pass. I removed it. Core headers also had no
compression set, so `readColors` threw an NPE for 16, 24 and 32 bit core header
bitmaps, even without `-ea`. They are uncompressed, so the compression is now
`BI_RGB`.
These listed under B in #1556 are invariants, so they stay:
- `HwmfBitmapDib:240,242`: `readHeader` forces the header size to 12 or 40,
and the color table has at most 256 entries
- `HwmfEmbeddedIterator:120,123`: `moveNext` only stops on valid EMF escapes
New tests, which fail without the change:
- `TestHemfPlusObject`: an unknown image type; a record reading past its
size; a pen id outside 0-63
- `TestHwmfBitmapDib`: a 24 bit core header bitmap; an unknown compression
The hemf and hwmf test packages and the HSLF and HWPF `TestPictures` pass on
JDK 17.
An unknown compression value in a `BitmapInfoHeader` is read as null, and
`readColors` switched on it, which threw an NPE for bitmaps of more than 8 bits
per pixel. It now throws the "Invalid compression option" `IOException` that
`readColors` already uses for a compression that doesn't fit the bit count.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]