aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java16
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java7
3 files changed, 24 insertions, 0 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index ea93e88316..e4a391cd11 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -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>
diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
index 52735db7fe..341f56b833 100644
--- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
@@ -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)];
@@ -100,6 +103,19 @@ public class SXSSFRow implements Row
}
/**
+ * @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.
*
* @param cell the cell to remove
diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
index c453203ac9..5e2aba7b0a 100644
--- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
@@ -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;