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:
parent
1ce1f599bf
commit
1f41c31984
@ -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.
|
* If the default font is changed the resized image can be streched vertically or horizontally.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void resize(){
|
public void resize(){
|
||||||
resize(Double.MAX_VALUE);
|
resize(Double.MAX_VALUE);
|
||||||
}
|
}
|
||||||
@ -112,6 +113,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
|
|||||||
*
|
*
|
||||||
* @see #resize(double, double)
|
* @see #resize(double, double)
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void resize(double scale) {
|
public void resize(double scale) {
|
||||||
resize(scale,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 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.
|
* @param scaleY the amount by which the image height is multiplied relative to the original height.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public void resize(double scaleX, double scaleY) {
|
public void resize(double scaleX, double scaleY) {
|
||||||
HSSFClientAnchor anchor = getClientAnchor();
|
HSSFClientAnchor anchor = getClientAnchor();
|
||||||
anchor.setAnchorType(AnchorType.MOVE_DONT_RESIZE);
|
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
|
* @return HSSFClientAnchor with the preferred size for this image
|
||||||
* @since POI 3.0.2
|
* @since POI 3.0.2
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public HSSFClientAnchor getPreferredSize(){
|
public HSSFClientAnchor getPreferredSize(){
|
||||||
return getPreferredSize(1.0);
|
return getPreferredSize(1.0);
|
||||||
}
|
}
|
||||||
@ -180,6 +184,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
|
|||||||
* @return HSSFClientAnchor with the preferred size for this image
|
* @return HSSFClientAnchor with the preferred size for this image
|
||||||
* @since POI 3.11
|
* @since POI 3.11
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public HSSFClientAnchor getPreferredSize(double scaleX, double scaleY){
|
public HSSFClientAnchor getPreferredSize(double scaleX, double scaleY){
|
||||||
ImageUtils.setPreferredSize(this, scaleX, scaleY);
|
ImageUtils.setPreferredSize(this, scaleX, scaleY);
|
||||||
return getClientAnchor();
|
return getClientAnchor();
|
||||||
@ -190,6 +195,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
|
|||||||
*
|
*
|
||||||
* @return image dimension in pixels
|
* @return image dimension in pixels
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public Dimension getImageDimension(){
|
public Dimension getImageDimension(){
|
||||||
InternalWorkbook iwb = getPatriarch().getSheet().getWorkbook().getWorkbook();
|
InternalWorkbook iwb = getPatriarch().getSheet().getWorkbook().getWorkbook();
|
||||||
EscherBSERecord bse = iwb.getBSERecord(getPictureIndex());
|
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
|
* @return picture data for this shape or {@code null} if picture wasn't embedded, i.e. external linked
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public HSSFPictureData getPictureData(){
|
public HSSFPictureData getPictureData(){
|
||||||
|
int picIdx = getPictureIndex();
|
||||||
|
if (picIdx == -1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
HSSFPatriarch patriarch = getPatriarch();
|
HSSFPatriarch patriarch = getPatriarch();
|
||||||
HSSFShape parent = getParent();
|
HSSFShape parent = getParent();
|
||||||
while(patriarch == null && parent != null) {
|
while(patriarch == null && parent != null) {
|
||||||
@ -215,7 +227,7 @@ public class HSSFPicture extends HSSFSimpleShape implements Picture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
InternalWorkbook iwb = patriarch.getSheet().getWorkbook().getWorkbook();
|
InternalWorkbook iwb = patriarch.getSheet().getWorkbook().getWorkbook();
|
||||||
EscherBSERecord bse = iwb.getBSERecord(getPictureIndex());
|
EscherBSERecord bse = iwb.getBSERecord(picIdx);
|
||||||
EscherBlipRecord blipRecord = bse.getBlipRecord();
|
EscherBlipRecord blipRecord = bse.getBlipRecord();
|
||||||
return new HSSFPictureData(blipRecord);
|
return new HSSFPictureData(blipRecord);
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
|
|||||||
@Override
|
@Override
|
||||||
public boolean canExtract(Picture source) {
|
public boolean canExtract(Picture source) {
|
||||||
PictureData pd = source.getPictureData();
|
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 :( )
|
// check for emf+ embedded pdf (poor mans style :( )
|
||||||
// Mac Excel 2011 embeds pdf files with this method.
|
// Mac Excel 2011 embeds pdf files with this method.
|
||||||
PictureData pd = source.getPictureData();
|
PictureData pd = source.getPictureData();
|
||||||
if (pd.getPictureType() != Workbook.PICTURE_TYPE_EMF) {
|
if (pd != null && pd.getPictureType() != Workbook.PICTURE_TYPE_EMF) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,7 +384,9 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
|
|||||||
int[] failure = computeFailure(pattern);
|
int[] failure = computeFailure(pattern);
|
||||||
|
|
||||||
int j = 0;
|
int j = 0;
|
||||||
if (data.length == 0) return -1;
|
if (data.length == 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = offset; i < data.length; i++) {
|
for (int i = offset; i < data.length; i++) {
|
||||||
while (j > 0 && pattern[j] != data[i]) {
|
while (j > 0 && pattern[j] != data[i]) {
|
||||||
|
BIN
test-data/spreadsheet/external_image.xls
Normal file
BIN
test-data/spreadsheet/external_image.xls
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user