From 936bf2f9b35abc7e54945f163745a594e32d9a57 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Mon, 12 Sep 2011 13:03:04 +0000 Subject: [PATCH] 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 --- src/documentation/content/xdocs/status.xml | 1 + .../org/apache/poi/hssf/record/LabelRecord.java | 13 ++++++++++++- .../org/apache/poi/hssf/usermodel/TestBugs.java | 6 ++++++ test-data/spreadsheet/51670.xls | Bin 0 -> 15360 bytes 4 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test-data/spreadsheet/51670.xls 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 0000000000000000000000000000000000000000..e7c929d9e593e36146b06763066e5f9d3fc1cd94 GIT binary patch literal 15360 zcmeI3Yiu0V701u4cfC)0Z6{7_5+_T@!*N20^Rz)BPDmgrkVGUjg;Eid7Y6cx1SnEb z-O^U7)K*B9Dgk|jPi? zfl?LfSVJnp%VGqW%Kw)3?opSk39OB`2Qi@i6Ix7HXu&^@O+I?PhK;rYFZ zi3txh)9vi>F|xqBk`@1PPIVOJ;F8WZo$WfyI@JZNQ)idXIXdU+?AAF?=X{+#I(v0q zqH}@Hg*vBeXDS(H>;Cf=xXDiGch)Ml(@v_q&mNMOW`4}GOfBYXV?z`2M+aV;|LWdf z2l4UZpjyAr?zTIe9CtUNY!2?SR1mjHbIhowpxaL`i=IF1-TQ6-!?u^C|1j;xX=m^M z|16NtX%uhG*v0POWM8V z?r8q#AcLBzekJ^gFFxvqvcNLIHjPeWHfs0SM_-$>#_g`LbCN2mEe8iA(+N9jXEbi_ zQTd=sM)DJq^rR$R%7d?+U>T|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