pjfanning opened a new pull request, #1557: URL: https://github.com/apache/poi/pull/1557
Part of #1556 (group A). These asserts check data read from files, but they only run with `-ea`. Without it, the code went on to throw a `NullPointerException` or `ArrayIndexOutOfBoundsException`, or read data at the wrong offset. Where a value is only stored during parsing and used later, the check now happens where it's used. Throwing at parse time would reject files that can be parsed today, e.g. for text or embedded image extraction. | Site | Before, without `-ea` | Now | |---|---|---| | `HemfPlusObject.init` | NPE on an unknown object type | `RecordFormatException` | | `HemfPlusBrush` | NPE in `getBrushData` for an unknown brush type | `IllegalStateException` from `getBrushData`, as its javadoc already says | | `HemfPlusImage` / `HemfPlusGDIImageRenderer` | NPE in `readGDIImage` for an unknown pixel format | `IllegalStateException`, like an unsupported one | | `HemfPlusImage.getContentType`, `HemfEmbeddedIterator` | NPE on an unknown image or metafile type | unknown content / embedded type | | `HemfComment` | `IllegalArgumentException` from a negative skip | `RecordFormatException`, like `HemfRecordIterator` | | `HwmfFill` / `HwmfGraphics.drawImage` | NPE when drawing with an unknown raster op, or with none set yet | drawn like `SRCCOPY`, the switch's default branch | | `HwmfBitmap16` | `skip()` can skip less than asked without being at the end | `skipFully` | | HSLF `EMF` / `WMF` blips | data shorter than its header went on to inflate from the wrong offset | `RecordFormatException` | | `HSLFTextParagraph.getAutoNumberingStartAt` | NPE unboxing null without an auto numbered bullet, and an index of -1 for level -1 | `null`, like the other auto numbering getters | | `HSLFSlideShowEncrypted.addEncryptionRecord` | `ArrayIndexOutOfBoundsException` without PersistPtrHolder/UserEditAtom | `CorruptPowerPointFileException`, only in the branch that needs them | | `XSLFTable.updateCellAnchor` | spans past the table were skipped cell by cell with a warning | loops stop at the table end, with one warning | The opcode check in `HwmfFill.readRasterOperation` and the CONTINUED check in `HemfEmbeddedIterator` stay as asserts. They are group B, spec checks where parsing carries on. Some of the asserts listed under A in #1556 turned out to be invariants, so they stay: - `HemfComment:271`: `getById` falls back to `emfGeneric` - `HemfEmbeddedIterator:231,290`: `moveNext` only stops on image objects - `HemfPlusRegion:324`: only operation node types create an `EmfPlusRegionNode` - `HwmfTernaryRasterOp:445`: all 256 operations have an argument order - `HSLFTable:208`: rows and columns come from the same anchors one loop earlier - `HSLFSlideShowEncrypted:556`: the caller creates the atom - `POIFSMiniStore:74`: `getBlockAt` throws rather than returning null - `CryptoAPIDecryptor:222`: decoding n UTF-16 units always gives n chars - `XSSFPivotCacheDefinition:135`: checked a few lines earlier New tests, which fail without the change: - `TestHemfPlusObject`: unknown object type; unknown brush type parses, then fails when used - `TestHwmfGraphics`: drawing an image with no raster op set - `TestHSLFSlideShowEncrypted`: adding the encryption record without the persist records - `TestXSLFTable.testSpanPastTableEnd` The hemf and hwmf test packages, `TestPictures`, `TestNumberedList*` and `TestXSLFTable` pass on JDK 17. 🤖 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]
