diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index ef8c2d1b7..dcadc73a8 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 51834 - Opening and Writing .doc file results in corrupt document 51902 - Picture.fillRawImageContent - ArrayIndexOutOfBoundsException (duplicate) 51890 - ArrayIndexOutOfBounds ExceptionPicture.fillRawImageContent Allow the passing of a File object to WorkbookFactory.create, which permits lower memory processing than the InputStream version diff --git a/src/java/org/apache/poi/hpsf/VariantSupport.java b/src/java/org/apache/poi/hpsf/VariantSupport.java index 1075a9cf8..af7347b71 100644 --- a/src/java/org/apache/poi/hpsf/VariantSupport.java +++ b/src/java/org/apache/poi/hpsf/VariantSupport.java @@ -482,8 +482,7 @@ public class VariantSupport extends Variant else trueOrFalse = (short) 0x0000; TypeWriter.writeUShortToStream( out, trueOrFalse ); - TypeWriter.writeUShortToStream( out, (short) 0x0000 ); - length += 4; + length += 2; break; } case Variant.VT_LPSTR: @@ -515,9 +514,6 @@ public class VariantSupport extends Variant out.write(highb); length += 2; } - out.write(0x00); - out.write(0x00); - length += 2; break; } case Variant.VT_CF: @@ -536,13 +532,7 @@ public class VariantSupport extends Variant case Variant.VT_I2: { TypeWriter.writeToStream(out, ((Integer) value).shortValue()); - // length = LittleEndianConsts.SHORT_SIZE; - TypeWriter.writeToStream( out, (short) 0x0000 ); - /* - * MUST be a 16-bit signed integer, followed by zero padding to 4 - * bytes -- http://msdn.microsoft.com/en-us/library/dd942532(v=PROT.13).aspx - */ - length = LittleEndianConsts.INT_SIZE; + length = LittleEndianConsts.SHORT_SIZE; break; } case Variant.VT_I4: @@ -599,6 +589,13 @@ public class VariantSupport extends Variant } } + /* pad values to 4-bytes */ + while ( ( length & 0x3 ) != 0 ) + { + out.write( 0x00 ); + length++; + } + return length; } } diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java index 50b6e5279..686f29706 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java @@ -17,7 +17,9 @@ package org.apache.poi.hwpf.usermodel; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; @@ -25,6 +27,7 @@ import java.util.Collection; import java.util.List; import junit.framework.TestCase; + import org.apache.commons.codec.digest.DigestUtils; import org.apache.poi.POIDataSamples; import org.apache.poi.hwpf.HWPFDocument; @@ -38,6 +41,7 @@ import org.apache.poi.hwpf.model.PlexOfField; import org.apache.poi.hwpf.model.SubdocumentType; import org.apache.poi.hwpf.model.io.HWPFOutputStream; import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; @@ -700,4 +704,19 @@ public class TestBugs extends TestCase + " has type " + pictureType ); } } + + /** + * [RESOLVED FIXED] Bug 51834 - Opening and Writing .doc file results in + * corrupt document + */ + public void testBug51834() throws Exception + { + /* + * we don't have Java test for this file - it should be checked using + * Microsoft BFF Validator. But check read-write-read anyway. -- sergey + */ + HWPFTestDataSamples.openSampleFile( "Bug51834.doc" ); + HWPFTestDataSamples.writeOutAndReadBack( HWPFTestDataSamples + .openSampleFile( "Bug51834.doc" ) ); + } } diff --git a/test-data/document/Bug51834.doc b/test-data/document/Bug51834.doc new file mode 100644 index 000000000..c1628251d Binary files /dev/null and b/test-data/document/Bug51834.doc differ