validate row and column indexes in SXSSF

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1243232 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2012-02-12 10:44:17 +00:00
parent 1d8365e7a3
commit 7e7bde2595
3 changed files with 24 additions and 0 deletions

View 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>

View 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.
*

View 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;