#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
This commit is contained in:
Andreas Beeker 2021-01-06 23:14:45 +00:00
parent 4c0d0b1381
commit 2125c37d31
3 changed files with 16 additions and 9 deletions

View File

@ -143,10 +143,10 @@ public final class HwmfDraw {
@Override @Override
public int init(LittleEndianInputStream leis, long recordSize, int recordFunction) throws IOException { 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. //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); poly = new Path2D.Double(Path2D.WIND_EVEN_ODD, numberOfPoints);
for (int i=0; i<numberofPoints; i++) { for (int i=0; i<numberOfPoints; i++) {
// A 16-bit signed integer that defines the horizontal (x) coordinate of the point. // A 16-bit signed integer that defines the horizontal (x) coordinate of the point.
int x = leis.readShort(); int x = leis.readShort();
// A 16-bit signed integer that defines the vertical (y) coordinate of the point. // 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 // polygons are closed / polylines not
poly.closePath(); poly.closePath();
} }
return LittleEndianConsts.SHORT_SIZE+numberofPoints*LittleEndianConsts.INT_SIZE; return LittleEndianConsts.SHORT_SIZE+numberOfPoints*LittleEndianConsts.INT_SIZE;
} }
@Override @Override

View File

@ -39,6 +39,8 @@ import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.RecordFormatException; import org.apache.poi.util.RecordFormatException;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
public class TestHwmfParsing { public class TestHwmfParsing {
@ -48,12 +50,17 @@ public class TestHwmfParsing {
// for manual mass parsing and rendering tests of .wmfs use HemfPictureTest.paint() ! // for manual mass parsing and rendering tests of .wmfs use HemfPictureTest.paint() !
// ****************************************************************************** // ******************************************************************************
@Test @ParameterizedTest
public void parse() throws IOException { @CsvSource({
try (InputStream fis = samples.openResourceAsStream("santa.wmf")) { "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); HwmfPicture wmf = new HwmfPicture(fis);
List<HwmfRecord> records = wmf.getRecords(); List<HwmfRecord> records = wmf.getRecords();
assertEquals(581, records.size()); assertEquals(recordCnt, records.size());
} }
} }

Binary file not shown.