Browse Source

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
tags/REL_3_8_BETA5
Sergey Vladimirov 12 years ago
parent
commit
026f46dbcc

+ 1
- 0
src/documentation/content/xdocs/status.xml View File

@@ -34,6 +34,7 @@

<changes>
<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">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>

+ 9
- 12
src/java/org/apache/poi/hpsf/VariantSupport.java View File

@@ -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;
}
}

+ 19
- 0
src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java View File

@@ -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" ) );
}
}

BIN
test-data/document/Bug51834.doc View File


Loading…
Cancel
Save