From 70fdc04369c6cfa1b4d71b838213b8248c8c9969 Mon Sep 17 00:00:00 2001 From: Sergey Vladimirov Date: Sat, 9 Jul 2011 15:33:41 +0000 Subject: [PATCH] temporary(?) workaround for Bug 49933 - Word 6/95 documents with sections cause ArrayIndexOutOfBoundsException git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1144683 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/org/apache/poi/hwpf/model/SEPX.java | 68 +++++++++++-------- .../poi/hwpf/usermodel/TestProblems.java | 5 ++ 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java index b6ae393d67..60e7d70af5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SEPX.java @@ -19,45 +19,59 @@ package org.apache.poi.hwpf.model; import org.apache.poi.hwpf.sprm.SectionSprmCompressor; import org.apache.poi.hwpf.sprm.SectionSprmUncompressor; +import org.apache.poi.hwpf.sprm.SprmBuffer; import org.apache.poi.hwpf.usermodel.SectionProperties; -/** - */ public final class SEPX extends BytePropertyNode { - SectionDescriptor _sed; + SectionProperties sectionProperties; - public SEPX(SectionDescriptor sed, int start, int end, CharIndexTranslator translator, byte[] grpprl) - { - super(start, end, translator, SectionSprmUncompressor.uncompressSEP(grpprl, 0)); - _sed = sed; - } + SectionDescriptor _sed; - public byte[] getGrpprl() - { - return SectionSprmCompressor.compressSectionProperty((SectionProperties)_buf); - } + public SEPX( SectionDescriptor sed, int start, int end, + CharIndexTranslator translator, byte[] grpprl ) + { + super( start, end, translator, new SprmBuffer( grpprl ) ); + _sed = sed; + } + + public byte[] getGrpprl() + { + if ( sectionProperties != null ) + { + byte[] grpprl = SectionSprmCompressor + .compressSectionProperty( sectionProperties ); + _buf = new SprmBuffer( grpprl ); + } + + return ( (SprmBuffer) _buf ).toByteArray(); + } - public SectionDescriptor getSectionDescriptor() - { - return _sed; - } + public SectionDescriptor getSectionDescriptor() + { + return _sed; + } - public SectionProperties getSectionProperties() - { - return (SectionProperties)_buf; - } + public SectionProperties getSectionProperties() + { + if ( sectionProperties == null ) + { + sectionProperties = SectionSprmUncompressor.uncompressSEP( + ( (SprmBuffer) _buf ).toByteArray(), 0 ); + } + return sectionProperties; + } - public boolean equals(Object o) - { - SEPX sepx = (SEPX)o; - if (super.equals(o)) + public boolean equals( Object o ) { - return sepx._sed.equals(_sed); + SEPX sepx = (SEPX) o; + if ( super.equals( o ) ) + { + return sepx._sed.equals( _sed ); + } + return false; } - return false; - } public String toString() { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java index f52df00e71..387b3cb20f 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestProblems.java @@ -793,6 +793,11 @@ public final class TestProblems extends HWPFTestCase { } } + public void test49933() + { + HWPFTestDataSamples.openOldSampleFile( "Bug49933.doc" ); + } + /** * Bug 50936 - HWPF fails to read a file */ -- 2.39.5