From: Sergey Vladimirov Date: Sat, 29 Oct 2011 23:57:48 +0000 (+0000) Subject: fix additional issue found in bug 52032, add test files X-Git-Tag: REL_3_8_BETA5~39 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a430d57858606cc35abc5db528886948e64d4c3a;p=poi.git fix additional issue found in bug 52032, add test files git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1195077 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java index 9d4d97a655..e33ccb2d96 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java @@ -38,71 +38,23 @@ import org.apache.poi.util.POILogger; @Internal public final class ListLevel { - private static final POILogger logger = POILogFactory.getLogger( ListLevel.class ); - + private static final POILogger logger = POILogFactory + .getLogger( ListLevel.class ); + private byte[] _grpprlChpx; private byte[] _grpprlPapx; private LVLF _lvlf; private char[] _xst = {}; - public ListLevel( final byte[] buf, final int startOffset ) + ListLevel() { - int offset = startOffset; - _lvlf = new LVLF( buf, offset ); - offset += LVLF.getSize(); - - _grpprlPapx = new byte[_lvlf.getCbGrpprlPapx()]; - System.arraycopy( buf, offset, _grpprlPapx, 0, _lvlf.getCbGrpprlPapx() ); - offset += _lvlf.getCbGrpprlPapx(); - - _grpprlChpx = new byte[_lvlf.getCbGrpprlChpx()]; - System.arraycopy( buf, offset, _grpprlChpx, 0, _lvlf.getCbGrpprlChpx() ); - offset += _lvlf.getCbGrpprlChpx(); - - /* - * "If this level uses bullets (see lvlf.nfc), the cch field of this Xst - * MUST be equal to 0x0001, and this MUST NOT contain any placeholders." - * -- page 389 of 621 -- [MS-DOC] -- v20110315 Word (.doc) Binary File - * Format - */ - if ( _lvlf.getNfc() == 0x17 ) - { - int numberTextLength = LittleEndian.getShort( buf, offset ); - offset += LittleEndian.SHORT_SIZE; - - if ( numberTextLength != 1 ) - { - logger.log( POILogger.WARN, "LVL at offset ", - Integer.valueOf( startOffset ), - " has nfc == 0x17 (bullets), but cch != 1 (", - Integer.valueOf( numberTextLength ), ")" ); - } - - _xst = new char[] { (char) LittleEndian.getShort( buf, offset ) }; - offset += LittleEndian.SHORT_SIZE; - } - else - { - int numberTextLength = LittleEndian.getShort( buf, offset ); - offset += LittleEndian.SHORT_SIZE; + } - if ( numberTextLength > 0 ) - { - _xst = new char[numberTextLength]; - for ( int x = 0; x < numberTextLength; x++ ) - { - _xst[x] = (char) LittleEndian.getShort( buf, offset ); - offset += LittleEndian.SHORT_SIZE; - } - } - else - { - /* sometimes numberTextLength<0 */ - /* by derjohng */ - _xst = new char[] {}; - } - } + @Deprecated + public ListLevel( final byte[] buf, final int startOffset ) + { + read( buf, startOffset ); } public ListLevel( int level, boolean numbered ) @@ -206,6 +158,74 @@ public final class ListLevel return _lvlf.getIxchFollow(); } + int read( final byte[] data, final int startOffset ) + { + int offset = startOffset; + + _lvlf = new LVLF( data, offset ); + offset += LVLF.getSize(); + + _grpprlPapx = new byte[_lvlf.getCbGrpprlPapx()]; + System.arraycopy( data, offset, _grpprlPapx, 0, _lvlf.getCbGrpprlPapx() ); + offset += _lvlf.getCbGrpprlPapx(); + + _grpprlChpx = new byte[_lvlf.getCbGrpprlChpx()]; + System.arraycopy( data, offset, _grpprlChpx, 0, _lvlf.getCbGrpprlChpx() ); + offset += _lvlf.getCbGrpprlChpx(); + + /* + * "If this level uses bullets (see lvlf.nfc), the cch field of this Xst + * MUST be equal to 0x0001, and this MUST NOT contain any placeholders." + * -- page 389 of 621 -- [MS-DOC] -- v20110315 Word (.doc) Binary File + * Format + */ + if ( _lvlf.getNfc() == 0x17 ) + { + int cch = LittleEndian.getUShort( data, offset ); + offset += LittleEndian.SHORT_SIZE; + + if ( cch != 1 ) + { + logger.log( POILogger.WARN, "LVL at offset ", + Integer.valueOf( startOffset ), + " has nfc == 0x17 (bullets), but cch != 1 (", + Integer.valueOf( cch ), ")" ); + } + + _xst = new char[cch]; + for ( int x = 0; x < cch; x++ ) + { + _xst[x] = (char) LittleEndian.getShort( data, offset ); + offset += LittleEndian.SHORT_SIZE; + } + } + else + { + int cch = LittleEndian.getUShort( data, offset ); + offset += LittleEndian.SHORT_SIZE; + + if ( cch > 0 ) + { + _xst = new char[cch]; + for ( int x = 0; x < cch; x++ ) + { + _xst[x] = (char) LittleEndian.getShort( data, offset ); + offset += LittleEndian.SHORT_SIZE; + } + } + else + { + logger.log( POILogger.WARN, "LVL.xst.cch <= 0: ", + Integer.valueOf( cch ) ); + /* sometimes numberTextLength<0 */ + /* by derjohng */ + _xst = new char[] {}; + } + } + + return offset - startOffset; + } + public void setAlignment( int alignment ) { _lvlf.setJc( (byte) alignment ); @@ -276,9 +296,10 @@ public final class ListLevel @Override public String toString() { - return "ListLevel: " + ( "\n" + _lvlf ).replaceAll( "\n", "\n " ) + return "LVL: " + ( "\n" + _lvlf ).replaceAll( "\n", "\n " ) + "\n" + ( "PAPX's grpprl: " + Arrays.toString( _grpprlPapx ) + "\n" ) - + ( "CHPX's grpprl: " + Arrays.toString( _grpprlChpx ) + "\n" ); + + ( "CHPX's grpprl: " + Arrays.toString( _grpprlChpx ) + "\n" ) + + ( "xst: " + Arrays.toString( _xst ) + "\n" ); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java index 88524d0f77..009f42f7b4 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java @@ -41,7 +41,6 @@ import org.apache.poi.util.POILogger; @Internal public final class ListTables { - private static final int LIST_DATA_SIZE = 28; private static POILogger log = POILogFactory.getLogger(ListTables.class); ListMap _listMap = new ListMap(); @@ -65,7 +64,7 @@ public final class ListTables int cLst = LittleEndian.getShort( tableStream, offset ); offset += LittleEndian.SHORT_SIZE; - int levelOffset = offset + ( cLst * LIST_DATA_SIZE ); + int levelOffset = offset + ( cLst * LSTF.getSize() ); for ( int x = 0; x < cLst; x++ ) { @@ -76,9 +75,9 @@ public final class ListTables int num = lst.numLevels(); for ( int y = 0; y < num; y++ ) { - ListLevel lvl = new ListLevel( tableStream, levelOffset ); + ListLevel lvl = new ListLevel(); + levelOffset += lvl.read( tableStream, levelOffset ); lst.setLevel( y, lvl ); - levelOffset += lvl.getSizeInBytes(); } } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java new file mode 100644 index 0000000000..90919cfcc0 --- /dev/null +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java @@ -0,0 +1,34 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ +package org.apache.poi.hwpf.model.types; + +import junit.framework.TestCase; + +/** + * Test cases for {@link LFOLVLBaseAbstractType} + * + * @author Sergey Vladimirov (vlsergey {at} gmail {dot} com) + */ +public class LFOLVLBaseAbstractTypeTest extends TestCase +{ + + public void testGetSize() + { + assertEquals( 8, LFOLVLBaseAbstractType.getSize() ); + } + +} diff --git a/test-data/document/Bug52032.doc b/test-data/document/Bug52032.doc deleted file mode 100644 index c91d240bf9..0000000000 Binary files a/test-data/document/Bug52032.doc and /dev/null differ diff --git a/test-data/document/Bug52032_1.doc b/test-data/document/Bug52032_1.doc new file mode 100644 index 0000000000..adfa972adc Binary files /dev/null and b/test-data/document/Bug52032_1.doc differ diff --git a/test-data/document/Bug52032_2.doc b/test-data/document/Bug52032_2.doc new file mode 100644 index 0000000000..cc0ede1651 Binary files /dev/null and b/test-data/document/Bug52032_2.doc differ diff --git a/test-data/document/Bug52032_3.doc b/test-data/document/Bug52032_3.doc new file mode 100644 index 0000000000..c91d240bf9 Binary files /dev/null and b/test-data/document/Bug52032_3.doc differ