]> source.dussan.org Git - poi.git/commitdiff
Apply patch from Jukka from bug #43670 to improve HDGF v11 Separator detection, and...
authorNick Burch <nick@apache.org>
Thu, 28 Jan 2010 12:05:13 +0000 (12:05 +0000)
committerNick Burch <nick@apache.org>
Thu, 28 Jan 2010 12:05:13 +0000 (12:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@904052 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java
src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeaderV11.java
src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java
test-data/diagram/NegativeChunkLength2.vsd [new file with mode: 0644]

index b0ae08f9b9f098af6df041ce7e483d3d843f15fd..28c8f53b0f5464b30292db163924fa77942d47e7 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-SNAPSHOT" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">43670 - Improve HDGF ChunkV11 separator detection, and short string detection, to solve the "Negative length of ChunkHeader" problem</action>
            <action dev="POI-DEVELOPERS" type="add">48617 - Optionally allow the overriding of the Locale used by DataFormatter to control how the default number and date formats should look</action>
            <action dev="POI-DEVELOPERS" type="add">New event based xssf text extractor (XSSFEventBasedExcelExtractor)</action>
            <action dev="POI-DEVELOPERS" type="add">ExtractorFactory can now be told to prefer Event Based extractors (current Excel only) on a per-thread or overall basis</action>
index 64314ee5f0f16a523891d8611b467c82cb82b104..595ca9ad928d5337d82283983e860337fbbd0875 100644 (file)
@@ -180,6 +180,14 @@ public final class Chunk {
                                // A Little Endian String
                                // Starts 8 bytes into the data segment
                                // Ends at end of data, or 00 00
+                          
+                               // Ensure we have enough data
+                               if(contents.length < 8) {
+                                       command.value = "";
+                                       break;
+                               }
+                          
+                               // Find the end point
                                int startsAt = 8;
                                int endsAt = startsAt;
                                for(int j=startsAt; j<contents.length-1 && endsAt == startsAt; j++) {
@@ -190,7 +198,7 @@ public final class Chunk {
                                if(endsAt == startsAt) {
                                        endsAt = contents.length;
                                }
-
+                               
                                int strLen = (endsAt-startsAt) / 2;
                                command.value = StringUtil.getFromUnicodeLE(contents, startsAt, strLen);
                                break;
index 1d3b763ece5562a3b5b4e246dd69ec2e193c23a0..df68ea5849415154840df3ec1c71776fac094437 100644 (file)
@@ -33,7 +33,10 @@ public final class ChunkHeaderV11 extends ChunkHeaderV6 {
                if(hasTrailer()) { return true; }
 
                if(unknown2 == 2 && unknown3 == 0x55) { return true; }
+               if(unknown2 == 2 && unknown3 == 0x54 && type == 0xa9) { return true; }
                if(unknown2 == 2 && unknown3 == 0x54 && type == 0xaa) { return true; }
+               if(unknown2 == 2 && unknown3 == 0x54 && type == 0xb4) { return true; }
+               if(unknown2 == 2 && unknown3 == 0x54 && type == 0xb6) { return true; }
                if(unknown2 == 3 && unknown3 != 0x50) { return true; }
                if(type == 0x69) { return true; }
 
index d6616b9147c706833087643a50b9ec03bc4e602f..67a4141768c410b8497f39a4b27e40873cc4dc34 100644 (file)
@@ -63,13 +63,18 @@ public final class TestHDGFCore extends TestCase {
        }
 
        /**
-        * Tests that we can open a problematic file, that initially
-        *  appears to have a negative chunk length
+        * Tests that we can open a problematic file, that used to
+        *  break with a negative chunk length
         */
-       public void DISABLEDtestNegativeChunkLength() throws Exception {
+       public void testNegativeChunkLength() throws Exception {
                fs = new POIFSFileSystem(_dgTests.openResourceAsStream("NegativeChunkLength.vsd"));
 
                HDGFDiagram hdgf = new HDGFDiagram(fs);
                assertNotNull(hdgf);
+               
+               // And another file
+               fs = new POIFSFileSystem(_dgTests.openResourceAsStream("NegativeChunkLength2.vsd"));
+               hdgf = new HDGFDiagram(fs);
+               assertNotNull(hdgf);
        }
 }
diff --git a/test-data/diagram/NegativeChunkLength2.vsd b/test-data/diagram/NegativeChunkLength2.vsd
new file mode 100644 (file)
index 0000000..3ca5552
Binary files /dev/null and b/test-data/diagram/NegativeChunkLength2.vsd differ