summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Beeker <kiwiwings@apache.org>2015-12-14 22:49:04 +0000
committerAndreas Beeker <kiwiwings@apache.org>2015-12-14 22:49:04 +0000
commit2ac3e0f3e8a8d94bcc493ddc19793b831dfc854a (patch)
treef56c944647cb90449acb645a7f2f4565a0c90385
parentb1841058358ad240717d347c393167b45f4e4161 (diff)
downloadpoi-2ac3e0f3e8a8d94bcc493ddc19793b831dfc854a.tar.gz
poi-2ac3e0f3e8a8d94bcc493ddc19793b831dfc854a.zip
#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
-rw-r--r--src/java/org/apache/poi/sl/usermodel/TableShape.java19
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java17
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java2
-rw-r--r--src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java30
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java9
-rw-r--r--test-data/slideshow/bug58733_671884.pptbin0 -> 224256 bytes
6 files changed, 65 insertions, 12 deletions
diff --git a/src/java/org/apache/poi/sl/usermodel/TableShape.java b/src/java/org/apache/poi/sl/usermodel/TableShape.java
index 5070cf4052..13c5d0dc52 100644
--- a/src/java/org/apache/poi/sl/usermodel/TableShape.java
+++ b/src/java/org/apache/poi/sl/usermodel/TableShape.java
@@ -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);
/**
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java
index d0d474944a..21472d709b 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java
@@ -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
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java
index 4fe197782e..737d2927a2 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java
@@ -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;
}
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java
index 814ffe7455..b82bed34a6 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java
@@ -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
diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
index 6e11a41b54..68684bf8d6 100644
--- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
+++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
@@ -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);
diff --git a/test-data/slideshow/bug58733_671884.ppt b/test-data/slideshow/bug58733_671884.ppt
new file mode 100644
index 0000000000..08c46e0558
--- /dev/null
+++ b/test-data/slideshow/bug58733_671884.ppt
Binary files differ