--- src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java (revision 9090) +++ src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java (working copy) @@ -65,6 +65,7 @@ */ public StyleSheet(byte[] tableStream, int offset) { + int startOffset = offset; _stshiLength = LittleEndian.getShort(tableStream, offset); offset += LittleEndian.SHORT_SIZE; int stdCount = LittleEndian.getShort(tableStream, offset); @@ -88,7 +89,7 @@ _rgftc[2] = LittleEndian.getShort(tableStream, offset); offset += LittleEndian.SHORT_SIZE; - offset = (LittleEndian.SHORT_SIZE + _stshiLength); + offset = startOffset + LittleEndian.SHORT_SIZE + _stshiLength; _styleDescriptions = new StyleDescription[stdCount]; for(int x = 0; x < stdCount; x++) { --- src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java (revision 9090) +++ src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java (working copy) @@ -46,6 +46,21 @@ } + public void testReadWriteFromNonZeroOffset() + throws Exception + { + HWPFFileSystem fileSys = new HWPFFileSystem(); + HWPFOutputStream tableOut = fileSys.getStream("1Table"); + + tableOut.write(new byte[20]); // 20 bytes of whatever at the front. + _styleSheet.writeTo(tableOut); + + byte[] newTableStream = tableOut.toByteArray(); + + StyleSheet newStyleSheet = new StyleSheet(newTableStream, 20); + assertEquals(newStyleSheet, _styleSheet); + } + protected void setUp() throws Exception {