diff options
author | Nick Burch <nick@apache.org> | 2009-11-04 00:07:37 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2009-11-04 00:07:37 +0000 |
commit | 4ca0b5535ffe681dd88bf0b36795e0e3fad4c468 (patch) | |
tree | 24f0fb4f6ee0f8583aff975ce23bb3e393caa0ab /src/scratchpad | |
parent | 70e958022610fd290c05f5c1ba4d1e20d4b90a7f (diff) | |
download | poi-4ca0b5535ffe681dd88bf0b36795e0e3fad4c468.tar.gz poi-4ca0b5535ffe681dd88bf0b36795e0e3fad4c468.zip |
Patch from Trejkaz - fix bug #48038 - handle reading HWPF stylesheets from non zero offsets
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@832625 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad')
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java | 3 | ||||
-rw-r--r-- | src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java | 15 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java index edb74eace6..647746d82e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleSheet.java @@ -65,6 +65,7 @@ public final class StyleSheet implements HDFType { */ 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 @@ public final class StyleSheet implements HDFType { _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++) { diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java index d092441e0d..8bae9aba08 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestStyleSheet.java @@ -46,6 +46,21 @@ public final class TestStyleSheet } + 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 { |