From: Yegor Kozlov Date: Mon, 12 Sep 2011 13:03:04 +0000 (+0000) Subject: fixed bug 51670: avoid LeftoverDataException when reading .xls files with invalid... X-Git-Tag: REL_3_8_BETA5~174 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=936bf2f9b35abc7e54945f163745a594e32d9a57;p=poi.git 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 --- 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 @@ + 51670 - avoid LeftoverDataException when reading .xls files with invalid LabelRecords 51196 - prevent NPE in XWPFPicture.getPictureData() 51771 - prevent NPE when getting object data from OLEShape in HSLF 51196 - more progress with Chart APi in XSSF 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 Binary files /dev/null and b/test-data/spreadsheet/51670.xls differ