mirror of https://github.com/apache/poi.git
#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
This commit is contained in:
parent
b184105835
commit
2ac3e0f3e8
|
@ -21,10 +21,29 @@ public interface TableShape<
|
||||||
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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -55,7 +55,6 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
|
||||||
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);
|
||||||
|
|
||||||
|
@ -83,7 +82,21 @@ public class XSLFTable extends XSLFGraphicFrame implements Iterable<XSLFTableRow
|
||||||
|
|
||||||
@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
|
||||||
|
|
|
@ -58,7 +58,7 @@ public final class HSLFShapeFactory {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -114,20 +115,31 @@ implements HSLFShapeContainer, TableShape<HSLFShape,HSLFTextParagraph> {
|
||||||
super(escherRecord, parent);
|
super(escherRecord, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Gets a cell
|
|
||||||
*
|
|
||||||
* @param row the row index (0-based)
|
|
||||||
* @param col the column index (0-based)
|
|
||||||
* @return the cell
|
|
||||||
*/
|
|
||||||
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
|
||||||
|
|
|
@ -768,6 +768,15 @@ public final class TestBugs {
|
||||||
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);
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue