diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2021-01-06 23:14:45 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2021-01-06 23:14:45 +0000 |
commit | 2125c37d31050241f9f0dd3dcea111cd1bf7f134 (patch) | |
tree | 911b62b4e104dd73cddb2c7c4a8d2b82f4f69405 | |
parent | 4c0d0b138161682b800a9f63eb67c0a7ccfa73b4 (diff) | |
download | poi-2125c37d31050241f9f0dd3dcea111cd1bf7f134.tar.gz poi-2125c37d31050241f9f0dd3dcea111cd1bf7f134.zip |
#65063 - WMF parsing failed on closed empty polygon
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1885215 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hwmf/record/HwmfDraw.java | 10 | ||||
-rw-r--r-- | src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java | 15 | ||||
-rw-r--r-- | test-data/slideshow/empty-polygon-close.wmf | bin | 0 -> 20644 bytes |
3 files changed, 16 insertions, 9 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfDraw.java b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfDraw.java index 12eb580f93..1c99601642 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfDraw.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfDraw.java @@ -143,10 +143,10 @@ public final class HwmfDraw { @Override public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException { //A 16-bit signed integer that defines the number of points in the array. - int numberofPoints = leis.readShort(); + int numberOfPoints = leis.readShort(); - poly = new Path2D.Double(Path2D.WIND_EVEN_ODD, numberofPoints); - for (int i=0; i<numberofPoints; i++) { + poly = new Path2D.Double(Path2D.WIND_EVEN_ODD, numberOfPoints); + for (int i=0; i<numberOfPoints; i++) { // A 16-bit signed integer that defines the horizontal (x) coordinate of the point. int x = leis.readShort(); // A 16-bit signed integer that defines the vertical (y) coordinate of the point. @@ -158,12 +158,12 @@ public final class HwmfDraw { } } - if (addClose()) { + if (numberOfPoints > 0 && addClose()) { // polygons are closed / polylines not poly.closePath(); } - return LittleEndianConsts.SHORT_SIZE+numberofPoints*LittleEndianConsts.INT_SIZE; + return LittleEndianConsts.SHORT_SIZE+numberOfPoints*LittleEndianConsts.INT_SIZE; } @Override diff --git a/src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java b/src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java index ebb829a9b3..d1440c0c32 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java +++ b/src/scratchpad/testcases/org/apache/poi/hwmf/TestHwmfParsing.java @@ -39,6 +39,8 @@ import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.RecordFormatException; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; public class TestHwmfParsing { @@ -48,12 +50,17 @@ public class TestHwmfParsing { // for manual mass parsing and rendering tests of .wmfs use HemfPictureTest.paint() ! // ****************************************************************************** - @Test - public void parse() throws IOException { - try (InputStream fis = samples.openResourceAsStream("santa.wmf")) { + @ParameterizedTest + @CsvSource({ + "santa.wmf, 581", + /* Bug 65063 */ + "empty-polygon-close.wmf, 272" + }) + public void parse(String file, int recordCnt) throws IOException { + try (InputStream fis = samples.openResourceAsStream(file)) { HwmfPicture wmf = new HwmfPicture(fis); List<HwmfRecord> records = wmf.getRecords(); - assertEquals(581, records.size()); + assertEquals(recordCnt, records.size()); } } diff --git a/test-data/slideshow/empty-polygon-close.wmf b/test-data/slideshow/empty-polygon-close.wmf Binary files differnew file mode 100644 index 0000000000..44aa7cfe23 --- /dev/null +++ b/test-data/slideshow/empty-polygon-close.wmf |