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
This commit is contained in:
Yegor Kozlov 2011-09-12 13:03:04 +00:00
parent 05ddc358f6
commit 936bf2f9b3
4 changed files with 19 additions and 1 deletions

View 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>

View 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;
}
/**

View File

@ -2173,4 +2173,10 @@ if(1==2) {
assertTrue(text.contains("Bottom Right Cell"));
}
}
public void test51670() {
HSSFWorkbook wb = openSample("51670.xls");
writeOutAndReadBack(wb);
}
}

Binary file not shown.