poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1418264 - in /poi/trunk/src: documentation/content/xdocs/ ooxml/java/org/apache/poi/xssf/streaming/ ooxml/testcases/org/apache/poi/xssf/streaming/
Date Fri, 07 Dec 2012 10:36:20 GMT
Author: yegor
Date: Fri Dec  7 10:36:16 2012
New Revision: 1418264

URL: http://svn.apache.org/viewvc?rev=1418264&view=rev
Log:
Bug 53650  - Prevent unreadable content and disalow to overwrite rows in user templates

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFSheet.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1418264&r1=1418263&r2=1418264&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Dec  7 10:36:16 2012
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="4.0-beta1" date="2013-??-??">
+          <action dev="poi-developers" type="fix">53650 - Prevent unreadable content
and disalow to overwrite rows from input template in SXSSF</action>
           <action dev="poi-developers" type="fix">54228,53672 - Fixed XSSF to read
cells with missing R attribute</action>
           <action dev="poi-developers" type="fix">54206 - Ensure that shared formuals
are updated when shifting rows in a spreadsheet</action>
           <action dev="poi-developers" type="fix">Synchronize table headers with parent
sheet in XSSF</action>

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java?rev=1418264&r1=1418263&r2=1418264&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java Fri Dec  7 10:36:16
2012
@@ -106,6 +106,20 @@ public class SXSSFSheet implements Sheet
                     + ") outside allowable range (0.." + maxrow + ")");
         }
 
+        // attempt to overwrite a row that is already flushed to disk
+        if(rownum <= _writer.getLastFlushedRow() ) {
+            throw new IllegalArgumentException(
+                    "Attempting to write a row["+rownum+"] " +
+                    "in the range [0," + _writer.getLastFlushedRow() + "] that is already
written to disk.");
+        }
+
+        // attempt to overwrite a existing row in the input template
+        if(_sh.getPhysicalNumberOfRows() > 0 && rownum <= _sh.getLastRowNum()
) {
+            throw new IllegalArgumentException(
+                    "Attempting to write a row["+rownum+"] " +
+                            "in the range [0," + _sh.getLastRowNum() + "] that is already
written to disk.");
+        }
+
 //Make the initial allocation as big as the row above.
         Row previousRow=rownum>0?getRow(rownum-1):null;
         int initialAllocationSize=0;

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java?rev=1418264&r1=1418263&r2=1418264&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SheetDataWriter.java Fri Dec  7
10:36:16 2012
@@ -44,6 +44,7 @@ public class SheetDataWriter {
     int _numberOfFlushedRows;
     int _lowestIndexOfFlushedRows; // meaningful only of _numberOfFlushedRows>0
     int _numberOfCellsOfLastFlushedRow; // meaningful only of _numberOfFlushedRows>0
+    int _numberLastFlushedRow = -1; // meaningful only of _numberOfFlushedRows>0
 
     public SheetDataWriter() throws IOException {
         _fd = createTempFile();
@@ -105,6 +106,10 @@ public class SheetDataWriter {
         return _lowestIndexOfFlushedRows;
     }
 
+    public int getLastFlushedRow() {
+        return _numberLastFlushedRow;
+    }
+
     protected void finalize() throws Throwable {
         _fd.delete();
     }
@@ -118,6 +123,7 @@ public class SheetDataWriter {
     public void writeRow(int rownum, SXSSFRow row) throws IOException {
         if (_numberOfFlushedRows == 0)
             _lowestIndexOfFlushedRows = rownum;
+        _numberLastFlushedRow = Math.max(rownum, _numberLastFlushedRow);
         _numberOfCellsOfLastFlushedRow = row.getLastCellNum();
         _numberOfFlushedRows++;
         beginRow(rownum, row);

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFSheet.java?rev=1418264&r1=1418263&r2=1418264&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFSheet.java Fri Dec
 7 10:36:16 2012
@@ -19,8 +19,10 @@
 
 package org.apache.poi.xssf.streaming;
 
-import org.apache.poi.ss.usermodel.BaseTestSheet;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.SXSSFITestDataProvider;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 
 
 public class TestSXSSFSheet extends BaseTestSheet {
@@ -90,4 +92,44 @@ public class TestSXSSFSheet extends Base
     public void testDefaultColumnStyle() {
         //TODO column styles are not yet supported by XSSF
     }
+
+    public void testOverrideFlushedRows() {
+        Workbook wb = new SXSSFWorkbook(3);
+        Sheet sheet = wb.createSheet();
+
+        sheet.createRow(1);
+        sheet.createRow(2);
+        sheet.createRow(3);
+        sheet.createRow(4);
+        try {
+            sheet.createRow(1);
+            fail("expected exception");
+        } catch (Throwable e){
+            assertEquals("Attempting to write a row[1] in the range [0,1] that is already
written to disk.", e.getMessage());
+        }
+
+    }
+
+    public void testOverrideRowsInTemplate() {
+        XSSFWorkbook template = new XSSFWorkbook();
+        template.createSheet().createRow(1);
+
+        Workbook wb = new SXSSFWorkbook(template);
+        Sheet sheet = wb.getSheetAt(0);
+
+        try {
+            sheet.createRow(1);
+            fail("expected exception");
+        } catch (Throwable e){
+            assertEquals("Attempting to write a row[1] in the range [0,1] that is already
written to disk.", e.getMessage());
+        }
+        try {
+            sheet.createRow(0);
+            fail("expected exception");
+        } catch (Throwable e){
+            assertEquals("Attempting to write a row[0] in the range [0,1] that is already
written to disk.", e.getMessage());
+        }
+        sheet.createRow(2);
+
+    }
 }



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


Mime
View raw message