You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2026/09/20 20:06:10 UTC
(poi) branch trunk updated: [bug-69924] HwmfHeader: reject an invalid metafile type instead of throwing ArrayIndexOutOfBoundsException (#1333)
This is an automated email from the ASF dual-hosted git repository.
pjfanning pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git
The following commit(s) were added to refs/heads/trunk by this push:
new 373fd4a486 [bug-69924] HwmfHeader: reject an invalid metafile type instead of throwing ArrayIndexOutOfBoundsException (#1333)
373fd4a486 is described below
commit 373fd4a4863b79b3caf9317b0ec62e6773c0f963
Author: PJ Fanning <pj...@users.noreply.github.com>
AuthorDate: Sun Sep 20 21:06:02 2026 +0100
[bug-69924] HwmfHeader: reject an invalid metafile type instead of throwing ArrayIndexOutOfBoundsException (#1333)
The header type was used as an index into HwmfHeaderMetaType.values()
without a range check, so a file that is not a WMF failed with an
ArrayIndexOutOfBoundsException. Throw an IOException naming the type,
as HemfHeader does for an invalid EMF header.
Co-authored-by: Claude Opus 5 (1M context) <no...@anthropic.com>
---
.../main/java/org/apache/poi/hwmf/record/HwmfHeader.java | 7 ++++++-
.../test/java/org/apache/poi/hwmf/TestHwmfParsing.java | 8 ++++++++
test-data/poi-integration-exceptions.csv | 1 +
test-data/slideshow/bug69924.wmf | Bin 0 -> 246 bytes
4 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfHeader.java b/poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfHeader.java
index 43885e2f8f..a08b77c423 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfHeader.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfHeader.java
@@ -47,7 +47,12 @@ public class HwmfHeader implements GenericRecord {
public HwmfHeader(LittleEndianInputStream leis) throws IOException {
// Type (2 bytes): A 16-bit unsigned integer that defines the type of metafile
// MEMORYMETAFILE = 0x0001, DISKMETAFILE = 0x0002
- type = HwmfHeaderMetaType.values()[leis.readUShort()-1];
+ int typeId = leis.readUShort();
+ HwmfHeaderMetaType[] types = HwmfHeaderMetaType.values();
+ if (typeId < 1 || typeId > types.length) {
+ throw new IOException("Not a valid WMF header. Type: 0x" + Integer.toHexString(typeId));
+ }
+ type = types[typeId-1];
// HeaderSize (2 bytes): A 16-bit unsigned integer that defines the number
// of 16-bit words in the header.
diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwmf/TestHwmfParsing.java b/poi-scratchpad/src/test/java/org/apache/poi/hwmf/TestHwmfParsing.java
index be741abe3f..f6ba293ff8 100644
--- a/poi-scratchpad/src/test/java/org/apache/poi/hwmf/TestHwmfParsing.java
+++ b/poi-scratchpad/src/test/java/org/apache/poi/hwmf/TestHwmfParsing.java
@@ -84,6 +84,14 @@ public class TestHwmfParsing {
}
}
+ @Test
+ void testInvalidHeaderTypeBug69924() throws Exception {
+ try (InputStream is = samples.openResourceAsStream("bug69924.wmf")) {
+ IOException ex = assertThrows(IOException.class, () -> new HwmfPicture(is));
+ assertEquals("Not a valid WMF header. Type: 0xf600", ex.getMessage());
+ }
+ }
+
@Test
void testInvalid() throws Exception {
try (InputStream is = samples.openResourceAsStream("santa.wmf")) {
diff --git a/test-data/poi-integration-exceptions.csv b/test-data/poi-integration-exceptions.csv
index 96b8ebd4d1..61be2c94e3 100644
--- a/test-data/poi-integration-exceptions.csv
+++ b/test-data/poi-integration-exceptions.csv
@@ -363,6 +363,7 @@ spreadsheet/rde.imf.ru_sites_default_files_rde_documents_vodootvedenie_2020.xlsb
spreadsheet/rde.imf.ru_sites_default_files_rde_documents_vodootvedenie_2020.xlsb.xls,"handle,additional","HSSF,HPSF",,org.apache.poi.poifs.filesystem.OfficeXmlFileException,The supplied data appears to be in the Office 2007+ XML,
spreadsheet/crash-e329fca9087fe21bca4a80c8bc472a661c98d860.xls,handle,HSSF,,org.apache.poi.util.RecordFormatException,33198 bytes written but getRecordSize() reports 33194,
slideshow/61338.wmf,"handle,extract",HWMF,,org.apache.poi.util.RecordFormatException,Tried to skip 9699347 but skipped: 489,
+slideshow/bug69924.wmf,"handle,extract",HWMF,,java.io.IOException,Not a valid WMF header. Type: 0xf600,
slideshow/file-45.wmf,handle,HWMF,,org.apache.poi.util.RecordFormatException,The width or height specified in the header exceed the current limit,
spreadsheet/61294.emf,"handle,extract",HEMF,,org.apache.poi.util.RecordFormatException,java.lang.IllegalStateException: Unexpected end-of-file,
publisher/clusterfuzz-testcase-minimized-POIHPBFFuzzer-6325615354773504.pub,"handle,extract",HPBF,,java.lang.IllegalArgumentException,File invalid - failed to find document entry,
diff --git a/test-data/slideshow/bug69924.wmf b/test-data/slideshow/bug69924.wmf
new file mode 100644
index 0000000000..dc8546897e
Binary files /dev/null and b/test-data/slideshow/bug69924.wmf differ
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org