From 220b2638308534f360fa3011ebe1727224989d58 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Sun, 16 Feb 2014 19:35:55 +0000 Subject: [PATCH] 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 --- .../org/apache/poi/hpsf/CodePageString.java | 2 +- .../apache/poi/hpsf/basic/TestHPSFBugs.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/poi/hpsf/CodePageString.java b/src/java/org/apache/poi/hpsf/CodePageString.java index eaaa11e51b..b94cb67c13 100644 --- a/src/java/org/apache/poi/hpsf/CodePageString.java +++ b/src/java/org/apache/poi/hpsf/CodePageString.java @@ -42,7 +42,7 @@ class CodePageString offset += LittleEndian.INT_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 // triggering this for values that don't look like codepages // See Bug #52258 for details diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestHPSFBugs.java b/src/testcases/org/apache/poi/hpsf/basic/TestHPSFBugs.java index 05c8d8b99f..ff9ba878a5 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestHPSFBugs.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestHPSFBugs.java @@ -138,4 +138,27 @@ public final class TestHPSFBugs extends TestCase { assertEquals("", si.getAuthor()); 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()); + } } -- 2.39.5