Bug 69927: Avoid NPE when parsing wmf-file

headerBitCount can be null if the header contains an
invalid flag
This commit is contained in:
Dominik Stadler 2026-01-16 07:53:47 +01:00
parent b09bf904d7
commit 9c2f487c98
3 changed files with 8 additions and 2 deletions

View File

@ -243,7 +243,8 @@ public class HwmfBitmapDib implements GenericRecord {
// The size and format of this data is determined by information in the DIBHeaderInfo field. If
// it is a BitmapCoreHeader, the size in bytes MUST be calculated as follows:
int bodySize = ((((headerWidth * headerPlanes * headerBitCount.flag + 31) & ~31) / 8) * Math.abs(headerHeight));
int bodySize = ((((headerWidth * headerPlanes *
(headerBitCount == null ? 0 : headerBitCount.flag) + 31) & ~31) / 8) * Math.abs(headerHeight));
// This formula SHOULD also be used to calculate the size of aData when DIBHeaderInfo is a
// BitmapInfoHeader Object, using values from that object, but only if its Compression value is
@ -348,6 +349,10 @@ public class HwmfBitmapDib implements GenericRecord {
}
protected int readColors(LittleEndianInputStream leis) throws IOException {
if (headerBitCount == null) {
return 0;
}
switch (headerBitCount) {
default:
case BI_BITCOUNT_0:

View File

@ -54,7 +54,8 @@ public class TestHwmfParsing {
@CsvSource({
"santa.wmf, 581",
/* Bug 65063 */
"empty-polygon-close.wmf, 272"
"empty-polygon-close.wmf, 272",
"file-45.wmf, 1315"
})
void parse(String file, int recordCnt) throws IOException {
try (InputStream fis = samples.openResourceAsStream(file)) {

Binary file not shown.