From: Nick Burch Date: Sun, 19 Sep 2010 09:59:10 +0000 (+0000) Subject: More fixes for bug #49933, workaround the fact that some word6/word95 SEPX entries... X-Git-Tag: REL_3_7_BETA3~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0a60791f419be5c1b2fa54585c247281afcdfd56;p=poi.git More fixes for bug #49933, workaround the fact that some word6/word95 SEPX entries are compressed differently, and we don't have the specs for how they're stored git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@998621 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java index d16edb16be..87218b35e5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java @@ -56,7 +56,11 @@ public final class OldSectionTable extends SectionTable { // The first short at the offset is the size of the grpprl. int sepxSize = LittleEndian.getShort(documentStream, fileOffset); - byte[] buf = new byte[sepxSize]; + // Because we don't properly know about all the details of the old + // section properties, and we're trying to decode them as if they + // were the new ones, we sometimes "need" more data than we have. + // As a workaround, have a few extra 0 bytes on the end! + byte[] buf = new byte[sepxSize+2]; fileOffset += LittleEndian.SHORT_SIZE; System.arraycopy(documentStream, fileOffset, buf, 0, buf.length); _sections.add(new SEPX(sed, startAt, endAt, charConv, buf)); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHWPFOldDocument.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHWPFOldDocument.java index fc20c7157f..8eca387f0c 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHWPFOldDocument.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestHWPFOldDocument.java @@ -119,4 +119,24 @@ public final class TestHWPFOldDocument extends HWPFTestCase { assertEquals("\u000c", doc.getRange().getParagraph(4).text()); // Section line? assertEquals("\r", doc.getRange().getParagraph(5).text()); } + + /** + * Another word document with sections, this time with a + * few more section properties set on it + */ + public void testWord6Sections2() throws Exception { + HWPFOldDocument doc = HWPFTestDataSamples.openOldSampleFile("Word6_sections2.doc"); + + assertEquals(1, doc.getRange().numSections()); + assertEquals(57, doc.getRange().numParagraphs()); + + assertEquals( + "\r", + doc.getRange().getParagraph(0).text() + ); + assertEquals( + "STATEMENT OF INSOLVENCY PRACTICE 10 (SCOTLAND)\r", + doc.getRange().getParagraph(1).text() + ); + } } diff --git a/test-data/document/Word6_sections2.doc b/test-data/document/Word6_sections2.doc new file mode 100644 index 0000000000..d07da5bc1c Binary files /dev/null and b/test-data/document/Word6_sections2.doc differ