You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/12/14 23:49:05 UTC

svn commit: r1720035 - in /poi: site/src/documentation/content/xdocs/ trunk/src/java/org/apache/poi/sl/usermodel/ trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/ trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/ trunk/src/scratchpad/testcases...

Author: kiwiwings
Date: Mon Dec 14 22:49:04 2015
New Revision: 1720035

URL: http://svn.apache.org/viewvc?rev=1720035&view=rev
Log:
#58733 - New AIOOBE in getCell while iterating through a table in PPT

Added:
    poi/trunk/test-data/slideshow/bug58733_671884.ppt   (with props)
Modified:
    poi/site/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/sl/usermodel/TableShape.java
    poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java

Modified: poi/site/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/status.xml?rev=1720035&r1=1720034&r2=1720035&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/status.xml (original)
+++ poi/site/src/documentation/content/xdocs/status.xml Mon Dec 14 22:49:04 2015
@@ -40,7 +40,8 @@
     </devs>
 
     <release version="3.14-beta2" date="2016-??-??">
-        <action dev="PD" type="add" fixes-bug="58718">Master styles not initialized when running multithreaded</action>
+        <action dev="PD" type="fix" fixes-bug="58733">New AIOOBE in getCell while iterating through a table in PPT</action>
+        <action dev="PD" type="fix" fixes-bug="58718">Master styles not initialized when running multithreaded</action>
     </release>
 
     <release version="3.14-beta1" date="2015-12-14">

Modified: poi/trunk/src/java/org/apache/poi/sl/usermodel/TableShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/sl/usermodel/TableShape.java?rev=1720035&r1=1720034&r2=1720035&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/sl/usermodel/TableShape.java (original)
+++ poi/trunk/src/java/org/apache/poi/sl/usermodel/TableShape.java Mon Dec 14 22:49:04 2015
@@ -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);
     
     /**

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java?rev=1720035&r1=1720034&r2=1720035&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTable.java Mon Dec 14 22:49:04 2015
@@ -55,7 +55,6 @@ public class XSLFTable extends XSLFGraph
     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 XSLFGraph
 
     @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

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java?rev=1720035&r1=1720034&r2=1720035&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFShapeFactory.java Mon Dec 14 22:49:04 2015
@@ -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;
                 }

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java?rev=1720035&r1=1720034&r2=1720035&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTable.java Mon Dec 14 22:49:04 2015
@@ -52,6 +52,7 @@ implements HSLFShapeContainer, TableShap
 
 
     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, TableShap
         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

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java?rev=1720035&r1=1720034&r2=1720035&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestBugs.java Mon Dec 14 22:49:04 2015
@@ -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);

Added: poi/trunk/test-data/slideshow/bug58733_671884.ppt
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/slideshow/bug58733_671884.ppt?rev=1720035&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/slideshow/bug58733_671884.ppt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org