From 0a60791f419be5c1b2fa54585c247281afcdfd56 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sun, 19 Sep 2010 09:59:10 +0000 Subject: [PATCH] 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 --- .../poi/hwpf/model/OldSectionTable.java | 6 +++++- .../hwpf/usermodel/TestHWPFOldDocument.java | 20 ++++++++++++++++++ test-data/document/Word6_sections2.doc | Bin 0 -> 15360 bytes 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test-data/document/Word6_sections2.doc 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 0000000000000000000000000000000000000000..d07da5bc1c763521ed60b3b721e593af3f988978 GIT binary patch literal 15360 zcmeHOTWlQF89uwd#7kmw1*HMXNl=4BoFxv4b5Wt$_(B|P@8WexfTikqcI+M4-C1U4 z<5=n?h$2;L9w<;jC8~mi(+gFr7GA2-ingH*4^??6y-1XXmR7tJK^j4Ug8O}E=6El0 zoCHxM!cO%2KXc}s|NQs=oSDsYzgv3z(I2gPNz`4}i6-&hOiZ*^^+(WNs_&Nwu?%hY zy*D#6!)|m5G#l4PNCPiS=fu9_v1Z!O;vaoA39$tRj$E!gD)_|3pDn)PQX!(4 z_bFgr)p#xLZ$SU=fiJ%-!2bru(qb5Y_5&XQz7?4K%ynr!XnrWoLPS&a6i(}B>lqsB z6>bS7)RZ;WX4e5FHnDZ!nJ)Qb{YO4A=wDkU;EL!~Y$T3)wj`9cKmB4!5>9FQg z(<496VxH!!dW{dR-JTvzjP?!n4UbBh?3Z$2IGr54sc*RFW+_u6iJsAco<1qNHcHu% z?n#agCWd?0wYRsYMw0t6qCYt@lx}a=PuknNVxu|Rlb&z*R>3Oz(ixX_(R1<#tfDz3 zORi!1wrNR>af%k78q%{|+w#!mm94BCo05Lcl08njXxe#>;BDG5ZOfmMleVA3lm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