mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
Bug 69927: Avoid NPE when parsing wmf-file
headerBitCount can be null if the header contains an invalid flag
This commit is contained in:
parent
b09bf904d7
commit
9c2f487c98
@ -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:
|
||||
|
||||
@ -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)) {
|
||||
|
||||
BIN
test-data/slideshow/file-45.wmf
Normal file
BIN
test-data/slideshow/file-45.wmf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user