always pad properties to 4 bytes
fix 51834 - Opening and Writing .doc file results in corrupt document git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1178113 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
02f7229fa3
commit
99ee1edb17
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.8-beta5" date="2011-??-??">
|
<release version="3.8-beta5" date="2011-??-??">
|
||||||
|
<action dev="poi-developers" type="fix">51834 - Opening and Writing .doc file results in corrupt document</action>
|
||||||
<action dev="poi-developers" type="fix">51902 - Picture.fillRawImageContent - ArrayIndexOutOfBoundsException (duplicate)</action>
|
<action dev="poi-developers" type="fix">51902 - Picture.fillRawImageContent - ArrayIndexOutOfBoundsException (duplicate)</action>
|
||||||
<action dev="poi-developers" type="fix">51890 - ArrayIndexOutOfBounds ExceptionPicture.fillRawImageContent</action>
|
<action dev="poi-developers" type="fix">51890 - ArrayIndexOutOfBounds ExceptionPicture.fillRawImageContent</action>
|
||||||
<action dev="poi-developers" type="add">Allow the passing of a File object to WorkbookFactory.create, which permits lower memory processing than the InputStream version</action>
|
<action dev="poi-developers" type="add">Allow the passing of a File object to WorkbookFactory.create, which permits lower memory processing than the InputStream version</action>
|
||||||
|
@ -482,8 +482,7 @@ public class VariantSupport extends Variant
|
|||||||
else
|
else
|
||||||
trueOrFalse = (short) 0x0000;
|
trueOrFalse = (short) 0x0000;
|
||||||
TypeWriter.writeUShortToStream( out, trueOrFalse );
|
TypeWriter.writeUShortToStream( out, trueOrFalse );
|
||||||
TypeWriter.writeUShortToStream( out, (short) 0x0000 );
|
length += 2;
|
||||||
length += 4;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Variant.VT_LPSTR:
|
case Variant.VT_LPSTR:
|
||||||
@ -515,9 +514,6 @@ public class VariantSupport extends Variant
|
|||||||
out.write(highb);
|
out.write(highb);
|
||||||
length += 2;
|
length += 2;
|
||||||
}
|
}
|
||||||
out.write(0x00);
|
|
||||||
out.write(0x00);
|
|
||||||
length += 2;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Variant.VT_CF:
|
case Variant.VT_CF:
|
||||||
@ -536,13 +532,7 @@ public class VariantSupport extends Variant
|
|||||||
case Variant.VT_I2:
|
case Variant.VT_I2:
|
||||||
{
|
{
|
||||||
TypeWriter.writeToStream(out, ((Integer) value).shortValue());
|
TypeWriter.writeToStream(out, ((Integer) value).shortValue());
|
||||||
// length = LittleEndianConsts.SHORT_SIZE;
|
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;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Variant.VT_I4:
|
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;
|
return length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,9 @@
|
|||||||
package org.apache.poi.hwpf.usermodel;
|
package org.apache.poi.hwpf.usermodel;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -25,6 +27,7 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
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.SubdocumentType;
|
||||||
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
|
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
|
||||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
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.IOUtils;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
@ -700,4 +704,19 @@ public class TestBugs extends TestCase
|
|||||||
+ " has type " + pictureType );
|
+ " 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" ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
test-data/document/Bug51834.doc
Normal file
BIN
test-data/document/Bug51834.doc
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user