Browse Source

#58733 - New AIOOBE in getCell while iterating through a table in PPT

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1720035 13f79535-47bb-0310-9956-ffa450edef68
tags/REL_3_14_BETA1_RC2
Andreas Beeker 8 years ago
parent
commit
2ac3e0f3e8

+ 19
- 0
src/java/org/apache/poi/sl/usermodel/TableShape.java View File

@@ -21,10 +21,29 @@ public interface TableShape<
S extends Shape<S,P>,
P extends TextParagraph<S,P,?>
> extends Shape<S,P>, PlaceableShape<S,P> {
/**
* Return the maximum number of columns.
* If the table contains merged cells, the number of columns might be less than the maximum.
*
* @return the maximum number of column
*/
int getNumberOfColumns();
/**
* Return the number of rows
*
* @return the row count
*/
int getNumberOfRows();
/**
* Gets a cell
*
* @param row the row index (0-based)
* @param col the column index (0-based)
* @return the cell or null if the cell doesn't exists, e.g. when accessing
* a merged cell or if the index is out of bounds
*/
TableCell<S,P> getCell(int row, int col);
/**

+ 15
- 2
src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java View File

@@ -55,7 +55,6 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
private CTTable _table;
private List<XSLFTableRow> _rows;
@SuppressWarnings("deprecation")
/*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){
super(shape, sheet);
@@ -83,7 +82,21 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
@Override
public XSLFTableCell getCell(int row, int col) {
return getRows().get(row).getCells().get(col);
List<XSLFTableRow> rows = getRows();
if (row < 0 || rows.size() <= row) {
return null;
}
XSLFTableRow r = rows.get(row);
if (r == null) {
// empty row
return null;
}
List<XSLFTableCell> cells = r.getCells();
if (col < 0 || cells.size() <= col) {
return null;
}
// cell can be potentially empty ...
return cells.get(col);
}
@Internal

+ 1
- 1
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java View File

@@ -58,7 +58,7 @@ public final class HSLFShapeFactory {
for (EscherProperty ep : props) {
if (ep.getPropertyNumber() == EscherProperties.GROUPSHAPE__TABLEPROPERTIES
&& ep instanceof EscherSimpleProperty
&& ((EscherSimpleProperty)ep).getPropertyValue() == 1) {
&& (((EscherSimpleProperty)ep).getPropertyValue() & 1) == 1) {
isTable = true;
break;
}

+ 21
- 9
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java View File

@@ -52,6 +52,7 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {


protected HSLFTableCell[][] cells;
private int columnCount = -1;

/**
* Create a new Table of the given number of rows and columns
@@ -114,20 +115,31 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
super(escherRecord, parent);
}

/**
* Gets a cell
*
* @param row the row index (0-based)
* @param col the column index (0-based)
* @return the cell
*/
@Override
public HSLFTableCell getCell(int row, int col) {
return cells[row][col];
if (row < 0 || cells.length <= row) {
return null;
}
HSLFTableCell[] r = cells[row];
if (r == null || col < 0 || r.length <= col) {
// empty row
return null;
}
// cell can be potentially empty ...
return r[col];
}

@Override
public int getNumberOfColumns() {
return cells[0].length;
if (columnCount == -1) {
// check all rows in case of merged rows
for (HSLFTableCell[] hc : cells) {
if (hc != null) {
columnCount = Math.max(columnCount, hc.length);
}
}
}
return columnCount;
}

@Override

+ 9
- 0
src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java View File

@@ -768,6 +768,15 @@ public final class TestBugs {
ex.close();
}
}

@Test
public void bug58733() throws IOException {
File sample = HSLFTestDataSamples.getSampleFile("bug58733_671884.ppt");
PowerPointExtractor ex = new PowerPointExtractor(sample.getAbsolutePath());
assertNotNull(ex.getText());
ex.close();
}

private static HSLFSlideShow open(String fileName) throws IOException {
File sample = HSLFTestDataSamples.getSampleFile(fileName);

BIN
test-data/slideshow/bug58733_671884.ppt View File


Loading…
Cancel
Save