diff --git a/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java b/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java index 70df41135a..3dd5d189e3 100644 --- a/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java +++ b/src/scratchpad/src/org/apache/poi/hemf/record/emf/HemfComment.java @@ -39,6 +39,8 @@ import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianInputStream; import org.apache.poi.util.LocaleUtil; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; import org.apache.poi.util.RecordFormatException; /** @@ -46,6 +48,7 @@ import org.apache.poi.util.RecordFormatException; */ @Internal public class HemfComment { + private static final POILogger logger = POILogFactory.getLogger(HemfComment.class); private static final int MAX_RECORD_LENGTH = HwmfPicture.MAX_RECORD_LENGTH; public enum HemfCommentRecordType { @@ -557,7 +560,11 @@ public class HemfComment { wmfData = IOUtils.safelyAllocate(winMetafileSize, MAX_RECORD_LENGTH); // some emf comments are truncated, so we don't use readFully here - leis.read(wmfData); + int readBytes = leis.read(wmfData); + if (readBytes < wmfData.length) { + logger.log(POILogger.INFO, "Emf comment with WMF: expected "+wmfData.length+ + " bytes - received only "+readBytes+" bytes."); + } return leis.getReadIndex()-startIdx; } diff --git a/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java b/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java index 3b3b7fa393..9532826873 100644 --- a/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java +++ b/src/scratchpad/src/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java @@ -17,15 +17,7 @@ package org.apache.poi.hemf.usermodel; -import java.awt.Transparency; -import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; -import java.awt.image.ComponentColorModel; -import java.awt.image.DataBuffer; -import java.awt.image.DataBufferByte; -import java.awt.image.PixelInterleavedSampleModel; -import java.awt.image.Raster; -import java.awt.image.WritableRaster; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.ArrayDeque; @@ -38,7 +30,6 @@ import org.apache.poi.hemf.record.emf.HemfComment; import org.apache.poi.hemf.record.emf.HemfRecord; import org.apache.poi.hemf.record.emfplus.HemfPlusImage.EmfPlusBitmapDataType; import org.apache.poi.hemf.record.emfplus.HemfPlusImage.EmfPlusImage; -import org.apache.poi.hemf.record.emfplus.HemfPlusImage.EmfPlusPixelFormat; import org.apache.poi.hemf.record.emfplus.HemfPlusObject; import org.apache.poi.hemf.record.emfplus.HemfPlusObject.EmfPlusObject; import org.apache.poi.hwmf.record.HwmfBitmapDib; @@ -209,9 +200,12 @@ public class HemfEmbeddedIterator implements Iterator { EmfPlusImage img = epo.getObjectData(); assert(img.getImageDataType() != null); - HwmfEmbedded emb = getEmfPlusImageData(); + final HwmfEmbedded emb = getEmfPlusImageData(); + if (emb == null) { + return null; + } - HwmfEmbeddedType et; + final HwmfEmbeddedType et; switch (img.getImageDataType()) { case BITMAP: if (img.getBitmapType() == EmfPlusBitmapDataType.COMPRESSED) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java index 627ed808d6..3b57ccb3b8 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFAutoShape.java @@ -341,6 +341,9 @@ public class HSLFAutoShape extends HSLFTextShape implements AutoShape vertIter) { final ObjectFactory of = new ObjectFactory(); HSLFFreeformShape.EscapeInfo ei = getEscapeInfo(segElem); + if (ei == null) { + return; + } switch (ei) { case EXTENSION: break; diff --git a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java index 788ad62534..ee5912773f 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfEscape.java @@ -205,7 +205,7 @@ public class HwmfEscape implements HwmfRecord { int byteCount = leis.readUShort(); int size = 2*LittleEndianConsts.SHORT_SIZE; - escapeData = escapeFunction.constructor.get(); + escapeData = (escapeFunction == null) ? new WmfEscapeUnknownData() : escapeFunction.constructor.get(); size += escapeData.init(leis, byteCount, escapeFunction); return size;