]> source.dussan.org Git - poi.git/commitdiff
Fix bug #44593 - improved handling of short DVRecords
authorNick Burch <nick@apache.org>
Thu, 13 Mar 2008 13:20:09 +0000 (13:20 +0000)
committerNick Burch <nick@apache.org>
Thu, 13 Mar 2008 13:20:09 +0000 (13:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@636756 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/util/HSSFCellRangeAddress.java
src/testcases/org/apache/poi/hssf/data/Bug44593.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

index 9c1529aa59fd8c59ebee9ae09b6d802438b1549f..8c1a63ceb9fd1f2fe62237a6cdccf99d400a46b3 100644 (file)
@@ -36,6 +36,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">44593 - Improved handling of short DVRecords</actions>
            <action dev="POI-DEVELOPERS" type="add">28627 / 44580 - Fix Range.delete() in HWPF</action>
            <action dev="POI-DEVELOPERS" type="add">44539 - Support for area references in formulas of rows >= 32768</action>
            <action dev="POI-DEVELOPERS" type="add">44536 - Improved support for detecting read-only recommended files</action>
index 367c6b0c7a22d16c3b39d415b2af51eadd69793f..9213e0184ec2c0494af74e353b1636c911466eb4 100644 (file)
@@ -33,6 +33,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1-beta1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">44593 - Improved handling of short DVRecords</actions>
            <action dev="POI-DEVELOPERS" type="add">28627 / 44580 - Fix Range.delete() in HWPF</action>
            <action dev="POI-DEVELOPERS" type="add">44539 - Support for area references in formulas of rows >= 32768</action>
            <action dev="POI-DEVELOPERS" type="add">44536 - Improved support for detecting read-only recommended files</action>
index 438f5e59683f75976ecfef08a1bd8391b299551d..73804966fbedf026d4fb2aede7e2e1971c60f39a 100644 (file)
@@ -18,6 +18,9 @@ package org.apache.poi.hssf.util;
 
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.util.LittleEndian;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
+
 import java.util.ArrayList;
 
 /**
@@ -38,6 +41,8 @@ import java.util.ArrayList;
 
 public class HSSFCellRangeAddress
 {
+       private static POILogger logger = POILogFactory.getLogger(HSSFCellRangeAddress.class);
+       
     /**
      * Number of following ADDR structures
      */
@@ -74,8 +79,19 @@ public class HSSFCellRangeAddress
                {
             short first_row = in.readShort(); 
             short first_col = in.readShort();
-            short last_row  = in.readShort();
-            short last_col  = in.readShort();
+            
+            short last_row  = first_row;
+            short last_col  = first_col;
+            if(in.remaining() >= 4) {
+                   last_row  = in.readShort();
+                   last_col  = in.readShort();
+            } else {
+               // Ran out of data
+               // For now, issue a warning, finish, and 
+               //  hope for the best....
+               logger.log(POILogger.WARN, "Ran out of data reading cell references for DVRecord");
+               k = this.field_addr_number;
+            }
 
                        AddrStructure region = new AddrStructure(first_row, first_col, last_row, last_col);
                        this.field_regions_list.add(region);
diff --git a/src/testcases/org/apache/poi/hssf/data/Bug44593.xls b/src/testcases/org/apache/poi/hssf/data/Bug44593.xls
new file mode 100644 (file)
index 0000000..84d1311
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/Bug44593.xls differ
index f9bb362c7b0b87743c5ac3da4a00009f3f739b17..a1c28fa59e391c6993e6aafaf5e8b1f837c91d55 100644 (file)
@@ -1127,6 +1127,23 @@ extends TestCase {
         in.close();
         assertFalse(wb.isWriteProtected());
     }
+    
+    /**
+     * Some files were having problems with the DVRecord,
+     *  probably due to dropdowns
+     */
+    public void test44593() throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "Bug44593.xls"));
+        
+        // Used to blow up with an IllegalArgumentException
+        //  when creating a DVRecord
+        // Now won't, but no idea if this means we have
+        //  rubbish in the DVRecord or not...
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        in.close();
+        
+        assertEquals(2, wb.getNumberOfSheets());
+    }
 }