Skip to content

Commit ab196a7

Browse files
committed
Use log instead of assert when parsing emf-files
Assert effectively hides problem in provided input files.
1 parent da3d64d commit ab196a7

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emfplus/HemfPlusHeader.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2424
import java.util.Map;
2525
import java.util.function.Supplier;
2626

27+
import org.apache.logging.log4j.LogManager;
28+
import org.apache.logging.log4j.Logger;
2729
import org.apache.poi.common.usermodel.GenericRecord;
2830
import org.apache.poi.hemf.draw.HemfGraphics;
2931
import org.apache.poi.hemf.draw.HemfGraphics.EmfRenderState;
@@ -38,6 +40,8 @@ Licensed to the Apache Software Foundation (ASF) under one or more
3840

3941
@Internal
4042
public class HemfPlusHeader implements HemfPlusRecord {
43+
private static final Logger log = LogManager.getLogger(HemfPlusHeader.class);
44+
4145
/**
4246
* The GraphicsVersion enumeration defines versions of operating system graphics that are used to
4347
* create EMF+ metafiles.
@@ -89,7 +93,12 @@ public long init(LittleEndianInputStream leis, long dataSize, long recordId, int
8993
this.flags = flags;
9094
version.init(leis);
9195

92-
assert(version.getMetafileSignature() == 0xDBC01 && version.getGraphicsVersion() != null);
96+
if (version.getMetafileSignature() != 0xDBC01) {
97+
log.atWarn().log("Had invalid meta-file signature, expected " + 0xDBC01 + ", had: " + version.getMetafileSignature());
98+
}
99+
if (version.getGraphicsVersion() == null) {
100+
log.atWarn().log("Encountered empty graphics version in emf file");
101+
}
93102

94103
emfPlusFlags = leis.readUInt();
95104

Binary file not shown.

test-data/spreadsheet/stress.xls

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)