aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2011-09-12 13:03:04 +0000
committerYegor Kozlov <yegor@apache.org>2011-09-12 13:03:04 +0000
commit936bf2f9b35abc7e54945f163745a594e32d9a57 (patch)
treee2886157abb9b96e054639954c2ae342ddd98d93
parent05ddc358f65ae928970583b3c4432bdb82bccf0b (diff)
downloadpoi-936bf2f9b35abc7e54945f163745a594e32d9a57.tar.gz
poi-936bf2f9b35abc7e54945f163745a594e32d9a57.zip
fixed bug 51670: avoid LeftoverDataException when reading .xls files with invalid LabelRecord
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1169725 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/java/org/apache/poi/hssf/record/LabelRecord.java13
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java6
-rw-r--r--test-data/spreadsheet/51670.xlsbin0 -> 15360 bytes
4 files changed, 19 insertions, 1 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index 47bcd10b50..d8a08883d1 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -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>
diff --git a/src/java/org/apache/poi/hssf/record/LabelRecord.java b/src/java/org/apache/poi/hssf/record/LabelRecord.java
index 9661f991f4..4d2570272b 100644
--- a/src/java/org/apache/poi/hssf/record/LabelRecord.java
+++ b/src/java/org/apache/poi/hssf/record/LabelRecord.java
@@ -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;
}
/**
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
index d53e50783e..e64cd7240b 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
@@ -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
index 0000000000..e7c929d9e5
--- /dev/null
+++ b/test-data/spreadsheet/51670.xls
Binary files differ