Fix AIOOBE while extracting hssf pictures which are externally linked

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1790897 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2017-04-10 21:43:22 +00:00
parent f1c88e9b02
commit 1f113bc64a
3 changed files with 19 additions and 5 deletions

View File

@ -103,6 +103,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
* If the default font is changed the resized image can be streched vertically or horizontally.
* </p>
*/
@Override
public void resize(){
resize(Double.MAX_VALUE);
}
@ -112,6 +113,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
*
* @see #resize(double, double)
*/
@Override
public void resize(double scale) {
resize(scale,scale);
}
@ -133,6 +135,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
* @param scaleX the amount by which the image width is multiplied relative to the original width.
* @param scaleY the amount by which the image height is multiplied relative to the original height.
*/
@Override
public void resize(double scaleX, double scaleY) {
HSSFClientAnchor anchor = getClientAnchor();
anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE);
@ -157,6 +160,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
* @return HSSFClientAnchor with the preferred size for this image
* @since POI 3.0.2
*/
@Override
public HSSFClientAnchor getPreferredSize(){
return getPreferredSize(1.0);
}
@ -180,6 +184,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
* @return HSSFClientAnchor with the preferred size for this image
* @since POI 3.11
*/
@Override
public HSSFClientAnchor getPreferredSize(double scaleX, double scaleY){
ImageUtils.setPreferredSize(this, scaleX, scaleY);
return getClientAnchor();
@ -190,6 +195,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
*
* @return image dimension in pixels
*/
@Override
public Dimension getImageDimension(){
InternalWorkbook iwb = getPatriarch().getSheet().getWorkbook().getWorkbook();
EscherBSERecord bse = iwb.getBSERecord(getPictureIndex());
@ -201,9 +207,15 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
/**
* Return picture data for this shape
*
* @return picture data for this shape
* @return picture data for this shape or {@code null} if picture wasn't embedded, i.e. external linked
*/
@Override
public HSSFPictureData getPictureData(){
int picIdx = getPictureIndex();
if (picIdx == -1) {
return null;
}
HSSFPatriarch patriarch = getPatriarch();
HSSFShape parent = getParent();
while(patriarch == null && parent != null) {
@ -215,7 +227,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
}
InternalWorkbook iwb = patriarch.getSheet().getWorkbook().getWorkbook();
EscherBSERecord bse = iwb.getBSERecord(getPictureIndex());
EscherBSERecord bse = iwb.getBSERecord(picIdx);
EscherBlipRecord blipRecord = bse.getBlipRecord();
return new HSSFPictureData(blipRecord);
}

View File

@ -218,7 +218,7 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
@Override
public boolean canExtract(Picture source) {
PictureData pd = source.getPictureData();
return (pd.getPictureType() == Workbook.PICTURE_TYPE_EMF);
return (pd != null && pd.getPictureType() == Workbook.PICTURE_TYPE_EMF);
}
/**
@ -232,7 +232,7 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
// check for emf+ embedded pdf (poor mans style :( )
// Mac Excel 2011 embeds pdf files with this method.
PictureData pd = source.getPictureData();
if (pd.getPictureType() != Workbook.PICTURE_TYPE_EMF) {
if (pd != null && pd.getPictureType() != Workbook.PICTURE_TYPE_EMF) {
return null;
}
@ -384,7 +384,9 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
int[] failure = computeFailure(pattern);
int j = 0;
if (data.length == 0) return -1;
if (data.length == 0) {
return -1;
}
for (int i = offset; i < data.length; i++) {
while (j > 0 && pattern[j] != data[i]) {

Binary file not shown.