]> source.dussan.org Git - poi.git/commitdiff
fixed bug 51670: avoid LeftoverDataException when reading .xls files with invalid...
authorYegor Kozlov <yegor@apache.org>
Mon, 12 Sep 2011 13:03:04 +0000 (13:03 +0000)
committerYegor Kozlov <yegor@apache.org>
Mon, 12 Sep 2011 13:03:04 +0000 (13:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1169725 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/LabelRecord.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/51670.xls [new file with mode: 0644]

index 47bcd10b5080d3cc42aea8f5b9803554e21f221e..d8a08883d1e42723aa98f728500a31b69e7de4d7 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta5" date="2011-??-??">
+           <action dev="poi-developers" type="add">51670 - avoid LeftoverDataException when reading .xls files with invalid LabelRecords</action>
            <action dev="poi-developers" type="add">51196 - prevent NPE in XWPFPicture.getPictureData() </action>
            <action dev="poi-developers" type="add">51771 - prevent NPE when getting object data from OLEShape in HSLF</action>
            <action dev="poi-developers" type="add">51196 - more progress with Chart APi in XSSF</action>
index 9661f991f46bc67952a42cd28579db614f4fd899..4d2570272b9d486d3bcb3ff0c2a8103e258b9305 100644 (file)
@@ -18,6 +18,8 @@
 package org.apache.poi.hssf.record;
 
 import org.apache.poi.util.HexDump;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 
 /**
  * Label Record (0x0204) - read only support for strings stored directly in the cell..  Don't
@@ -29,6 +31,8 @@ import org.apache.poi.util.HexDump;
  * @see org.apache.poi.hssf.record.LabelSSTRecord
  */
 public final class LabelRecord extends Record implements CellValueRecordInterface {
+    private final static POILogger logger = POILogFactory.getLogger(LabelRecord.class);
+
     public final static short sid = 0x0204;
 
     private int               field_1_row;
@@ -62,6 +66,13 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
         } else {
             field_6_value = "";
         }
+
+        if (in.remaining() > 0) {
+           logger.log(POILogger.INFO,
+                   "LabelRecord data remains: " + in.remaining() +
+                           " : " + HexDump.toHex(in.readRemainder())
+           );
+        }
     }
 
 /*
@@ -97,7 +108,7 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
      */
     public boolean isUnCompressedUnicode()
     {
-        return (field_5_unicode_flag == 1);
+        return (field_5_unicode_flag & 0x01) != 0;
     }
 
     /**
index d53e50783e00524aea927a5170688a20dcefc2e5..e64cd7240bd0fa0e93b0193d1eaae17b348bd300 100644 (file)
@@ -2173,4 +2173,10 @@ if(1==2) {
           assertTrue(text.contains("Bottom Right Cell"));
        }
     }
+
+    public void test51670() {
+        HSSFWorkbook wb = openSample("51670.xls");
+        writeOutAndReadBack(wb);
+    }
+
 }
diff --git a/test-data/spreadsheet/51670.xls b/test-data/spreadsheet/51670.xls
new file mode 100644 (file)
index 0000000..e7c929d
Binary files /dev/null and b/test-data/spreadsheet/51670.xls differ