mirror of https://github.com/apache/poi.git
Bug 64130 -- handle empty worksheet names in OldSheetRecord more robustly.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1873863 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d5ba6195a5
commit
636cc83665
|
@ -327,6 +327,7 @@ public class TestAllFiles {
|
||||||
"spreadsheet/testEXCEL_95.xls",
|
"spreadsheet/testEXCEL_95.xls",
|
||||||
"spreadsheet/59074.xls",
|
"spreadsheet/59074.xls",
|
||||||
"spreadsheet/60284.xls",
|
"spreadsheet/60284.xls",
|
||||||
|
"spreadsheet/64130.xls",
|
||||||
|
|
||||||
// OOXML Strict is not yet supported, see bug #57699
|
// OOXML Strict is not yet supported, see bug #57699
|
||||||
"spreadsheet/SampleSS.strict.xlsx",
|
"spreadsheet/SampleSS.strict.xlsx",
|
||||||
|
|
|
@ -47,15 +47,17 @@ public final class OldSheetRecord {
|
||||||
field_2_visibility = in.readUByte();
|
field_2_visibility = in.readUByte();
|
||||||
field_3_type = in.readUByte();
|
field_3_type = in.readUByte();
|
||||||
int field_4_sheetname_length = in.readUByte();
|
int field_4_sheetname_length = in.readUByte();
|
||||||
in.mark(1);
|
if (field_4_sheetname_length > 0) {
|
||||||
byte b = in.readByte();
|
in.mark(1);
|
||||||
// if the sheet name starts with a 0, we need to skip one byte, otherwise the following records will
|
byte b = in.readByte();
|
||||||
// fail with a LeftOverDataException
|
// if the sheet name starts with a 0, we need to skip one byte, otherwise the following records will
|
||||||
if (b != 0) {
|
// fail with a LeftOverDataException
|
||||||
try {
|
if (b != 0) {
|
||||||
in.reset();
|
try {
|
||||||
} catch (IOException e) {
|
in.reset();
|
||||||
throw new RecordFormatException(e);
|
} catch (IOException e) {
|
||||||
|
throw new RecordFormatException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
field_5_sheetname = IOUtils.safelyAllocate(field_4_sheetname_length, MAX_RECORD_LENGTH);
|
field_5_sheetname = IOUtils.safelyAllocate(field_4_sheetname_length, MAX_RECORD_LENGTH);
|
||||||
|
|
|
@ -45,6 +45,7 @@ public class TestBiffDrawingToXml extends BaseXLSIteratingTest {
|
||||||
EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it as well
|
EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it as well
|
||||||
EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
|
EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
|
||||||
EXCLUDED.put("61300.xls", RecordFormatException.class);
|
EXCLUDED.put("61300.xls", RecordFormatException.class);
|
||||||
|
EXCLUDED.put("64130.xls", OldExcelFormatException.class); // BIFF 5
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -54,6 +54,7 @@ public class TestBiffViewer extends BaseXLSIteratingTest {
|
||||||
EXCLUDED.put("50833.xls", IllegalArgumentException.class); // "Name is too long" when setting username
|
EXCLUDED.put("50833.xls", IllegalArgumentException.class); // "Name is too long" when setting username
|
||||||
EXCLUDED.put("XRefCalc.xls", RuntimeException.class); // "Buffer overrun"
|
EXCLUDED.put("XRefCalc.xls", RuntimeException.class); // "Buffer overrun"
|
||||||
EXCLUDED.put("61300.xls", RecordFormatException.class);
|
EXCLUDED.put("61300.xls", RecordFormatException.class);
|
||||||
|
EXCLUDED.put("64130.xls", OldExcelFormatException.class); //Biff 5
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class TestEFBiffViewer extends BaseXLSIteratingTest {
|
||||||
EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
|
EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
|
||||||
EXCLUDED.put("XRefCalc.xls", RuntimeException.class); // "Buffer overrun"
|
EXCLUDED.put("XRefCalc.xls", RuntimeException.class); // "Buffer overrun"
|
||||||
EXCLUDED.put("61300.xls", RecordFormatException.class);
|
EXCLUDED.put("61300.xls", RecordFormatException.class);
|
||||||
|
EXCLUDED.put("64130.xls", OldExcelFormatException.class); //Biff 5
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -47,6 +47,7 @@ public class TestFormulaViewer extends BaseXLSIteratingTest {
|
||||||
EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it as well
|
EXCLUDED.put("43493.xls", RecordInputStream.LeftoverDataException.class); // HSSFWorkbook cannot open it as well
|
||||||
EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
|
EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
|
||||||
EXCLUDED.put("61300.xls", RecordFormatException.class);
|
EXCLUDED.put("61300.xls", RecordFormatException.class);
|
||||||
|
EXCLUDED.put("64130.xls", OldExcelFormatException.class); //Biff 5
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class TestReSave extends BaseXLSIteratingTest {
|
||||||
EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
|
EXCLUDED.put("44958_1.xls", RecordInputStream.LeftoverDataException.class);
|
||||||
EXCLUDED.put("XRefCalc.xls", RuntimeException.class); // "Buffer overrun"
|
EXCLUDED.put("XRefCalc.xls", RuntimeException.class); // "Buffer overrun"
|
||||||
EXCLUDED.put("61300.xls", RecordFormatException.class);
|
EXCLUDED.put("61300.xls", RecordFormatException.class);
|
||||||
|
EXCLUDED.put("64130.xls", OldExcelFormatException.class); //Biff 5
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class TestRecordLister extends BaseXLSIteratingTest {
|
||||||
EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 / Excel 5
|
EXCLUDED.put("60284.xls", OldExcelFormatException.class); // Biff 5 / Excel 5
|
||||||
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
|
EXCLUDED.put("testEXCEL_95.xls", OldExcelFormatException.class); // Biff 5 / Excel 95
|
||||||
EXCLUDED.put("61300.xls", RecordFormatException.class);
|
EXCLUDED.put("61300.xls", RecordFormatException.class);
|
||||||
|
EXCLUDED.put("64130.xls", OldExcelFormatException.class); //Biff 5
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -267,6 +267,10 @@ public final class TestOldExcelExtractor {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInputStreamNPOIHeader() throws IOException {
|
public void testInputStreamNPOIHeader() throws IOException {
|
||||||
|
//TODO: the worksheet names are currently mangled. They're treated
|
||||||
|
//as if UTF-16, but they're just ascii. Need to fix this.
|
||||||
|
//Is it possible that the leading 0 byte in the worksheet name is a signal
|
||||||
|
//that these worksheet names should be interpreted as ascii/1252?
|
||||||
File file = HSSFTestDataSamples.getSampleFile("FormulaRefs.xls");
|
File file = HSSFTestDataSamples.getSampleFile("FormulaRefs.xls");
|
||||||
try (InputStream stream = new FileInputStream(file);
|
try (InputStream stream = new FileInputStream(file);
|
||||||
OldExcelExtractor extractor = new OldExcelExtractor(stream)) {
|
OldExcelExtractor extractor = new OldExcelExtractor(stream)) {
|
||||||
|
@ -350,6 +354,17 @@ public final class TestOldExcelExtractor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSheetWithNoName() throws IOException {
|
||||||
|
File file = HSSFTestDataSamples.getSampleFile("64130.xls");
|
||||||
|
|
||||||
|
try (OldExcelExtractor ex = new OldExcelExtractor(file)) {
|
||||||
|
assertEquals(5, ex.getBiffVersion());
|
||||||
|
assertEquals(5, ex.getFileType());
|
||||||
|
assertContains(ex.getText(), "Dawn");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static class NoExitSecurityManager extends SecurityManager {
|
private static class NoExitSecurityManager extends SecurityManager {
|
||||||
@Override
|
@Override
|
||||||
public void checkPermission(Permission perm) {
|
public void checkPermission(Permission perm) {
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue