]> source.dussan.org Git - poi.git/commitdiff
Patch and test from Jon Iles from bug #56138 - HPSF code page strings can be zero...
authorNick Burch <nick@apache.org>
Sun, 16 Feb 2014 19:35:55 +0000 (19:35 +0000)
committerNick Burch <nick@apache.org>
Sun, 16 Feb 2014 19:35:55 +0000 (19:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1568813 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hpsf/CodePageString.java
src/testcases/org/apache/poi/hpsf/basic/TestHPSFBugs.java

index eaaa11e51b4ef8a0f44977005f40d9f97f899ac8..b94cb67c13020a5a1e89fd4f74f23488dadeb6b1 100644 (file)
@@ -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
index 05c8d8b99fc2aeff4ca9d500ece2f375cf9aaa86..ff9ba878a5ff6248ebdf5e8f1fab4d198f526469 100644 (file)
@@ -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());
+   }
 }