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

S extends Shape<S,P>, S extends Shape<S,P>,
P extends TextParagraph<S,P,?> P extends TextParagraph<S,P,?>
> extends Shape<S,P>, PlaceableShape<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(); int getNumberOfColumns();
/**
* Return the number of rows
*
* @return the row count
*/
int getNumberOfRows(); 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); TableCell<S,P> getCell(int row, int col);
/** /**

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

private CTTable _table; private CTTable _table;
private List<XSLFTableRow> _rows; private List<XSLFTableRow> _rows;
@SuppressWarnings("deprecation")
/*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){ /*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){
super(shape, sheet); super(shape, sheet);
@Override @Override
public XSLFTableCell getCell(int row, int col) { 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 @Internal

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

for (EscherProperty ep : props) { for (EscherProperty ep : props) {
if (ep.getPropertyNumber() == EscherProperties.GROUPSHAPE__TABLEPROPERTIES if (ep.getPropertyNumber() == EscherProperties.GROUPSHAPE__TABLEPROPERTIES
&& ep instanceof EscherSimpleProperty && ep instanceof EscherSimpleProperty
&& ((EscherSimpleProperty)ep).getPropertyValue() == 1) {
&& (((EscherSimpleProperty)ep).getPropertyValue() & 1) == 1) {
isTable = true; isTable = true;
break; break;
} }

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





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


/** /**
* Create a new Table of the given number of rows and columns * Create a new Table of the given number of rows and columns
super(escherRecord, parent); 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) { 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 @Override
public int getNumberOfColumns() { 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 @Override

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

ex.close(); 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 { private static HSLFSlideShow open(String fileName) throws IOException {
File sample = HSLFTestDataSamples.getSampleFile(fileName); File sample = HSLFTestDataSamples.getSampleFile(fileName);

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


Loading…
Cancel
Save