From: Yegor Kozlov Date: Thu, 13 Sep 2007 19:11:10 +0000 (+0000) Subject: fixed re-open of bug #42844. HSSFEventFactory silently skips unknown records that... X-Git-Tag: REL_3_0_2_BETA1~53 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0b8319bdcdcefea87e0cad3e1165c277f09e9a7a;p=poi.git fixed re-open of bug #42844. HSSFEventFactory silently skips unknown records that happen to be continued. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@575406 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/eventusermodel/HSSFEventFactory.java b/src/java/org/apache/poi/hssf/eventusermodel/HSSFEventFactory.java index 1cd80d535b..70c989c179 100644 --- a/src/java/org/apache/poi/hssf/eventusermodel/HSSFEventFactory.java +++ b/src/java/org/apache/poi/hssf/eventusermodel/HSSFEventFactory.java @@ -22,15 +22,7 @@ import java.io.InputStream; import java.io.IOException; import org.apache.poi.hssf.eventusermodel.HSSFUserException; -import org.apache.poi.hssf.record.RecordFormatException; -import org.apache.poi.hssf.record.Record; -import org.apache.poi.hssf.record.RecordInputStream; -import org.apache.poi.hssf.record.RecordFactory; -import org.apache.poi.hssf.record.ContinueRecord; -import org.apache.poi.hssf.record.DrawingRecord; -import org.apache.poi.hssf.record.DrawingGroupRecord; -import org.apache.poi.hssf.record.ObjRecord; -import org.apache.poi.hssf.record.TextObjectRecord; +import org.apache.poi.hssf.record.*; import org.apache.poi.poifs.filesystem.POIFSFileSystem; /** @@ -151,7 +143,7 @@ public class HSSFEventFactory { in.nextRecord(); sid = in.getSid();; - + // // for some reasons we have to make the workbook to be at least 4096 bytes // but if we have such workbook we fill the end of it with zeros (many zeros) @@ -215,7 +207,11 @@ public class HSSFEventFactory rec = lastRec; } else { - throw new RecordFormatException("Records should handle ContinueRecord internally. Should not see this exception"); + if (rec instanceof UnknownRecord) { + ;//silently skip records we don't know about + } else { + throw new RecordFormatException("Records should handle ContinueRecord internally. Should not see this exception"); + } } } diff --git a/src/testcases/org/apache/poi/hssf/data/42844.xls b/src/testcases/org/apache/poi/hssf/data/42844.xls new file mode 100644 index 0000000000..50bb5a85b8 Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/42844.xls differ diff --git a/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java b/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java index 055629fa48..bd936a0afc 100644 --- a/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java +++ b/src/testcases/org/apache/poi/hssf/eventusermodel/TestHSSFEventFactory.java @@ -76,6 +76,24 @@ public class TestHSSFEventFactory extends TestCase { } } + /** + * Unknown records can be continued. + * Check that HSSFEventFactory doesn't break on them. + * (the test file was provided in a reopen of bug #42844) + */ + public void testUnknownContinueRecords() throws Exception { + File f = new File(dirname + "/42844.xls"); + + HSSFRequest req = new HSSFRequest(); + MockHSSFListener mockListen = new MockHSSFListener(); + req.addListenerForAllRecords(mockListen); + + POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(f)); + HSSFEventFactory factory = new HSSFEventFactory(); + factory.processWorkbookEvents(req, fs); + + assertTrue("no errors while processing the file", true); + } private static class MockHSSFListener implements HSSFListener { private MockHSSFListener() {}