]> source.dussan.org Git - poi.git/commitdiff
Fix for readCompressedUnicode not moaning about length=0, from bug #44643
authorNick Burch <nick@apache.org>
Thu, 20 Mar 2008 11:02:39 +0000 (11:02 +0000)
committerNick Burch <nick@apache.org>
Thu, 20 Mar 2008 11:02:39 +0000 (11:02 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@639242 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/RecordInputStream.java
src/testcases/org/apache/poi/hssf/data/44643.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

index 431558ccc8a2fd9cdf1cf831c4f090f3d9300256..ba900b2a28d336b0c30e0d655fcd24f15c6873da 100755 (executable)
@@ -266,6 +266,9 @@ public class RecordInputStream extends InputStream
   }
     
   public String readCompressedUnicode(int length) {
+       if(length == 0) {
+               return "";
+       }
     if ((length < 0) || ((remaining() < length) && !isContinueNext())) {
             throw new IllegalArgumentException("Illegal length " + length);
     }
@@ -273,7 +276,7 @@ public class RecordInputStream extends InputStream
     StringBuffer buf = new StringBuffer(length);
     for (int i=0;i<length;i++) {
       if ((remaining() == 0) && (isContinueNext())) {
-        nextRecord();
+          nextRecord();
           int compressByte = readByte();
           if(compressByte != 0) throw new IllegalArgumentException("compressByte in continue records must be 0 while reading compressed unicode");
       }
diff --git a/src/testcases/org/apache/poi/hssf/data/44643.xls b/src/testcases/org/apache/poi/hssf/data/44643.xls
new file mode 100644 (file)
index 0000000..7ae5071
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/44643.xls differ
index b534a8bbfb5bc4dd4cc5f52e1fe784009405c4cd..05ba29d09eab6aa01462ce1d21f817d11b77d534 100644 (file)
@@ -1204,6 +1204,20 @@ extends TestCase {
         
         assertEquals(2, wb.getNumberOfSheets());
     }
+    
+    /**
+     * Used to give problems due to trying to read a zero
+     *  length string, but that's now properly handled
+     */
+    public void test44643() throws Exception {
+        FileInputStream in = new FileInputStream(new File(cwd, "44643.xls"));
+        
+        // Used to blow up with an IllegalArgumentException
+        HSSFWorkbook wb = new HSSFWorkbook(in);
+        in.close();
+        
+        assertEquals(1, wb.getNumberOfSheets());
+    }
 }