Patch and test from Jon Iles from bug #56138 - HPSF code page strings can be zero length

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1568813 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2014-02-16 19:35:55 +00:00
parent 53c90692ee
commit c144310a15
2 changed files with 24 additions and 1 deletions

View File

@ -42,7 +42,7 @@ class CodePageString
offset += LittleEndian.INT_SIZE; offset += LittleEndian.INT_SIZE;
_value = LittleEndian.getByteArray( data, offset, size ); _value = LittleEndian.getByteArray( data, offset, size );
if ( _value[size - 1] != 0 ) { if ( size != 0 && _value[size - 1] != 0 ) {
// TODO Some files, such as TestVisioWithCodepage.vsd, are currently // TODO Some files, such as TestVisioWithCodepage.vsd, are currently
// triggering this for values that don't look like codepages // triggering this for values that don't look like codepages
// See Bug #52258 for details // See Bug #52258 for details

View File

@ -138,4 +138,27 @@ public final class TestHPSFBugs extends TestCase {
assertEquals("", si.getAuthor()); assertEquals("", si.getAuthor());
assertEquals("Cour de Justice", dsi.getCompany()); assertEquals("Cour de Justice", dsi.getCompany());
} }
/**
* CodePage Strings can be zero length
*/
public void test56138() throws Exception {
DocumentInputStream dis;
POIFSFileSystem fs =
new POIFSFileSystem(_samples.openResourceAsStream("TestZeroLengthCodePage.mpp"));
dis = fs.createDocumentInputStream(SummaryInformation.DEFAULT_STREAM_NAME);
SummaryInformation si = (SummaryInformation)PropertySetFactory.create(dis);
dis = fs.createDocumentInputStream(DocumentSummaryInformation.DEFAULT_STREAM_NAME);
DocumentSummaryInformation dsi = (DocumentSummaryInformation)PropertySetFactory.create(dis);
// Test
assertEquals("MSProject", si.getApplicationName());
assertEquals("project1", si.getTitle());
assertEquals("Jon Iles", si.getAuthor());
assertEquals("", dsi.getCompany());
assertEquals(2, dsi.getSectionCount());
}
} }