]> source.dussan.org Git - poi.git/commitdiff
validate row and column indexes in SXSSF
authorYegor Kozlov <yegor@apache.org>
Sun, 12 Feb 2012 10:44:17 +0000 (10:44 +0000)
committerYegor Kozlov <yegor@apache.org>
Sun, 12 Feb 2012 10:44:17 +0000 (10:44 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1243232 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java

index ea93e883163d76c8a92c9c3bfff0d35dbff232e8..e4a391cd11cb561cb3116ec78bcccc26bd3b7805 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta6" date="2012-??-??">
+           <action dev="poi-developers" type="add">validate row number and column index in SXSSF when creating new rows / cells</action>
            <action dev="poi-developers" type="fix">51498 - fixed evaluation of blank cells in COUNTIF</action>
            <action dev="poi-developers" type="add">52576 - support changing external file references in HSSFWorkbook</action>
            <action dev="poi-developers" type="add">49896 - support external references in FormulaRenderer</action>
index 52735db7fe1fe3b9b1b716bf604005ff068c3fe1..341f56b833050e8c097929b287cd05c7a3825d9f 100644 (file)
@@ -20,6 +20,7 @@ package org.apache.poi.xssf.streaming;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
+import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Row;
@@ -88,6 +89,8 @@ public class SXSSFRow implements Row
      */
     public Cell createCell(int column, int type)
     {
+        checkBounds(column);
+
         if(column>=_cells.length)
         {
             SXSSFCell[] newCells=new SXSSFCell[Math.max(column+1,_cells.length*2)];
@@ -99,6 +102,19 @@ public class SXSSFRow implements Row
         return _cells[column];
     }
 
+    /**
+     * @throws RuntimeException if the bounds are exceeded.
+     */
+    private static void checkBounds(int cellIndex) {
+        SpreadsheetVersion v = SpreadsheetVersion.EXCEL2007;
+        int maxcol = SpreadsheetVersion.EXCEL2007.getLastColumnIndex();
+        if (cellIndex < 0 || cellIndex > maxcol) {
+            throw new IllegalArgumentException("Invalid column index (" + cellIndex
+                    + ").  Allowable column range for " + v.name() + " is (0.."
+                    + maxcol + ") or ('A'..'" + v.getLastColumnName() + "')");
+        }
+    }
+
     /**
      * Remove the Cell from this row.
      *
index c453203ac98c5298f93597e7e8b235bcfcf2d176..5e2aba7b0a650728be4dde19fe9ab0527b13715e 100644 (file)
@@ -22,6 +22,7 @@ import java.util.Iterator;
 import java.util.TreeMap;
 import java.util.Map;
 
+import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.usermodel.*;
 
 import org.apache.poi.ss.util.SheetUtil;
@@ -84,6 +85,12 @@ public class SXSSFSheet implements Sheet, Cloneable
      */
     public Row createRow(int rownum)
     {
+        int maxrow = SpreadsheetVersion.EXCEL2007.getLastRowIndex();
+        if (rownum < 0 || rownum > maxrow) {
+            throw new IllegalArgumentException("Invalid row number (" + rownum
+                    + ") outside allowable range (0.." + maxrow + ")");
+        }
+
 //Make the initial allocation as big as the row above.
         Row previousRow=rownum>0?getRow(rownum-1):null;
         int initialAllocationSize=0;