Bug 57456: Fix reading XLS with empty SSTRecord where Excel puts some random number in unique-strings-count-field
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1659650 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8d8c3eeae1
commit
e7615fdd34
@ -243,7 +243,14 @@ public final class SSTRecord extends ContinuableRecord {
|
|||||||
field_1_num_strings = in.readInt();
|
field_1_num_strings = in.readInt();
|
||||||
field_2_num_unique_strings = in.readInt();
|
field_2_num_unique_strings = in.readInt();
|
||||||
field_3_strings = new IntMapper<UnicodeString>();
|
field_3_strings = new IntMapper<UnicodeString>();
|
||||||
|
|
||||||
deserializer = new SSTDeserializer(field_3_strings);
|
deserializer = new SSTDeserializer(field_3_strings);
|
||||||
|
// Bug 57456: some Excel Sheets send 0 as field=1, but have some random number in field_2,
|
||||||
|
// we should not try to read the strings in this case.
|
||||||
|
if(field_1_num_strings == 0) {
|
||||||
|
field_2_num_unique_strings = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
deserializer.manufactureStrings( field_2_num_unique_strings, in );
|
deserializer.manufactureStrings( field_2_num_unique_strings, in );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,15 +47,16 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* decodes hexdump files and concatenates the results
|
* decodes hexdump files and concatenates the results
|
||||||
* @param hexDumpFileNames names of sample files in the hssf test data directory
|
* @param hexDumpFileNames names of sample files in the hssf test data directory
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private static byte[] concatHexDumps(String... hexDumpFileNames) {
|
private static byte[] concatHexDumps(String... hexDumpFileNames) throws IOException {
|
||||||
int nFiles = hexDumpFileNames.length;
|
int nFiles = hexDumpFileNames.length;
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(nFiles * 8228);
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(nFiles * 8228);
|
||||||
for (int i = 0; i < nFiles; i++) {
|
for (int i = 0; i < nFiles; i++) {
|
||||||
String sampleFileName = hexDumpFileNames[i];
|
String sampleFileName = hexDumpFileNames[i];
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleFileName);
|
||||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||||
try {
|
|
||||||
while (true) {
|
while (true) {
|
||||||
String line = br.readLine();
|
String line = br.readLine();
|
||||||
if (line == null) {
|
if (line == null) {
|
||||||
@ -64,9 +65,6 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
baos.write(HexRead.readFromString(line));
|
baos.write(HexRead.readFromString(line));
|
||||||
}
|
}
|
||||||
is.close();
|
is.close();
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return baos.toByteArray();
|
return baos.toByteArray();
|
||||||
@ -86,8 +84,9 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* SST is often split over several {@link ContinueRecord}s
|
* SST is often split over several {@link ContinueRecord}s
|
||||||
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public void testContinuedRecord() {
|
public void testContinuedRecord() throws IOException {
|
||||||
byte[] origData;
|
byte[] origData;
|
||||||
SSTRecord record;
|
SSTRecord record;
|
||||||
byte[] ser_output;
|
byte[] ser_output;
|
||||||
@ -288,11 +287,10 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
assertEquals( 2, record.countStrings() );
|
assertEquals( 2, record.countStrings() );
|
||||||
assertEquals( 3, record.getNumStrings() );
|
assertEquals( 3, record.getNumStrings() );
|
||||||
assertEquals( 2, record.getNumUniqueStrings() );
|
assertEquals( 2, record.getNumUniqueStrings() );
|
||||||
Iterator iter = record.getStrings();
|
Iterator<UnicodeString> iter = record.getStrings();
|
||||||
|
|
||||||
while ( iter.hasNext() )
|
while ( iter.hasNext() ) {
|
||||||
{
|
UnicodeString ucs = iter.next();
|
||||||
UnicodeString ucs = (UnicodeString) iter.next();
|
|
||||||
|
|
||||||
if ( ucs.equals( s1 ) )
|
if ( ucs.equals( s1 ) )
|
||||||
{
|
{
|
||||||
@ -1498,4 +1496,13 @@ public final class TestSSTRecord extends TestCase {
|
|||||||
assertEquals(src, dst);
|
assertEquals(src, dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void test57456() {
|
||||||
|
byte[] bytes = HexRead.readFromString("FC, 00, 08, 00, 00, 00, 00, 00, E1, 06, 00, 00");
|
||||||
|
RecordInputStream in = TestcaseRecordInputStream.create(bytes);
|
||||||
|
assertEquals(SSTRecord.sid, in.getSid());
|
||||||
|
SSTRecord src = new SSTRecord(in);
|
||||||
|
assertEquals(0, src.getNumStrings());
|
||||||
|
assertEquals(0, src.getNumUniqueStrings());
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2681,4 +2681,10 @@ public final class TestBugs extends BaseTestBugzillaIssues {
|
|||||||
s = wb.getSheetAt(0);
|
s = wb.getSheetAt(0);
|
||||||
assertEquals(refHttp, s.getRow(0).getCell(0).getCellFormula());
|
assertEquals(refHttp, s.getRow(0).getCell(0).getCellFormula());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test57456() throws IOException {
|
||||||
|
Workbook wb = openSample("57456.xls");
|
||||||
|
wb.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
test-data/spreadsheet/57456.xls
Normal file
BIN
test-data/spreadsheet/57456.xls
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user