This is an automated email from the ASF dual-hosted git repository.

centic9 pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git

commit d4178c1d5c2eaf46495ecd231a314cad6e040684
Author: Dominik Stadler <[email protected]>
AuthorDate: Sun Aug 16 09:54:40 2026 +0200

    Change assert to exception for an invalid EMF file
    
    Fixes https://issues.oss-fuzz.com/issues/543906434
---
 .../java/org/apache/poi/hemf/record/emf/HemfFill.java     |   5 ++++-
 .../org/apache/poi/hemf/usermodel/TestHemfPicture.java    |  11 +++++++++++
 test-data/poi-integration-exceptions.csv                  |   1 +
 ...se-minimized-POIFileHandlerFuzzer-5318384433823744.emf | Bin 0 -> 108 bytes
 4 files changed, 16 insertions(+), 1 deletion(-)

diff --git 
a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfFill.java 
b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfFill.java
index 6273ab5ff7..1569f4440e 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfFill.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfFill.java
@@ -52,6 +52,7 @@ import org.apache.poi.util.GenericRecordUtil;
 import org.apache.poi.util.IOUtils;
 import org.apache.poi.util.LittleEndianConsts;
 import org.apache.poi.util.LittleEndianInputStream;
+import org.apache.poi.util.RecordFormatException;
 
 public final class HemfFill {
     private static final Logger LOG = PoiLogManager.getLogger(HemfFill.class);
@@ -778,7 +779,9 @@ public final class HemfFill {
         }
 
         final int undefinedSpace2 = offBits-offCurr-cbBmi-undefinedSpace1;
-        assert(undefinedSpace2 >= 0);
+        if (undefinedSpace2 < 0) {
+            throw new RecordFormatException("Invalid value for 
undefinedSpace2: " + undefinedSpace2);
+        }
 
         leis.skipFully(undefinedSpace1);
 
diff --git 
a/poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java
 
b/poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java
index 7211a9de20..dd4699c2d3 100644
--- 
a/poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java
+++ 
b/poi-scratchpad/src/test/java/org/apache/poi/hemf/usermodel/TestHemfPicture.java
@@ -233,6 +233,17 @@ public class TestHemfPicture {
         }
     }
 
+    @Test
+    void testAssertion() throws Exception {
+        try (InputStream is = 
ss_samples.openResourceAsStream("clusterfuzz-testcase-minimized-POIFileHandlerFuzzer-5318384433823744.emf"))
 {
+            UnsynchronizedByteArrayOutputStream bos = 
UnsynchronizedByteArrayOutputStream.builder().get();
+            IOUtils.copy(is, bos);
+
+            HemfPicture pic = new HemfPicture(bos.toInputStream());
+            assertThrows(RecordFormatException.class, () -> pic.forEach(r -> 
{}));
+        }
+    }
+
     @Test
     void testHeaderDescriptionBoundsAreValidated() throws Exception {
         HemfHeader header = new HemfHeader();
diff --git a/test-data/poi-integration-exceptions.csv 
b/test-data/poi-integration-exceptions.csv
index f1ac698462..4a9ea16a24 100644
--- a/test-data/poi-integration-exceptions.csv
+++ b/test-data/poi-integration-exceptions.csv
@@ -395,3 +395,4 @@ 
slideshow/clusterfuzz-testcase-minimized-POIFileHandlerFuzzer-6060921738035200.w
 
spreadsheet/LIBRE_OFFICE-128382-0.xlsx,handle,XSSF,,org.apache.poi.ss.formula.FormulaParseException,Illegal
 table name
 
spreadsheet/LIBRE_OFFICE-116306-0.xlsx,extract,"XSSF,OPC",,org.apache.poi.util.RecordFormatException,Tried
 to allocate an array
 
spreadsheet/LIBRE_OFFICE-116306-0.xlsx,handle,XSSF,,org.apache.poi.util.RecordFormatException,Tried
 to allocate an array
+spreadsheet/clusterfuzz-testcase-minimized-POIFileHandlerFuzzer-5318384433823744.emf,"handle,extract",HEMF,,org.apache.poi.util.RecordFormatException,Invalid
 value for undefinedSpace2
diff --git 
a/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIFileHandlerFuzzer-5318384433823744.emf
 
b/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIFileHandlerFuzzer-5318384433823744.emf
new file mode 100644
index 0000000000..16435d199e
Binary files /dev/null and 
b/test-data/spreadsheet/clusterfuzz-testcase-minimized-POIFileHandlerFuzzer-5318384433823744.emf
 differ


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to