]> source.dussan.org Git - poi.git/commitdiff
Add in a (disabled) test for bug #43670 (not yet fixed)
authorNick Burch <nick@apache.org>
Sun, 28 Oct 2007 20:56:34 +0000 (20:56 +0000)
committerNick Burch <nick@apache.org>
Sun, 28 Oct 2007 20:56:34 +0000 (20:56 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@589417 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java
src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkHeader.java
src/scratchpad/testcases/org/apache/poi/hdgf/TestHDGFCore.java
src/scratchpad/testcases/org/apache/poi/hdgf/data/NegativeChunkLength.vsd [new file with mode: 0644]

index f1f9edfc0362ab04fbac30059729f636b7c9365f..bb6f918d16653dcf53bbe3e3a505d5de379a6645 100644 (file)
@@ -107,6 +107,12 @@ public class ChunkFactory {
                // Create the header
                ChunkHeader header = 
                        ChunkHeader.createChunkHeader(version, data, offset);
+               // Sanity check
+               if(header.length < 0) {
+                       throw new IllegalArgumentException("Found a chunk with a negative length, which isn't allowed");
+               }
+               
+               // How far up to look
                int endOfDataPos = offset + header.getLength() + header.getSizeInBytes();
                
                // Check we have enough data, and tweak the header size
index 86603a4b9721f5177c5a1d4446e7d801eda40783..0d17669c288d4a04e5f43300e658342015f57ca7 100644 (file)
@@ -45,6 +45,7 @@ public abstract class ChunkHeader {
                        ch.length   = (int)LittleEndian.getUInt(data, offset + 12);
                        ch.unknown2 = LittleEndian.getShort(data, offset + 16);
                        ch.unknown3 = (short)LittleEndian.getUnsignedByte(data, offset + 18);
+                       
                        return ch;
                } else if(documentVersion == 5) {
                        throw new RuntimeException("TODO");
index 70bf5fae065d8043bd89e1b5f73659549f5c8094..85f64df220642fdf72e6c3c6c8404d2d44598281 100644 (file)
@@ -25,11 +25,13 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import junit.framework.TestCase;
 
 public class TestHDGFCore extends TestCase {
-       POIFSFileSystem fs;
+       private POIFSFileSystem fs;
+       private String dirname;
+       private String filename;
        
        protected void setUp() throws Exception {
-               String dirname = System.getProperty("HDGF.testdata.path");
-               String filename = dirname + "/Test_Visio-Some_Random_Text.vsd";
+               dirname = System.getProperty("HDGF.testdata.path");
+               filename = dirname + "/Test_Visio-Some_Random_Text.vsd";
                fs = new POIFSFileSystem(new FileInputStream(filename));
        }
        
@@ -59,4 +61,16 @@ public class TestHDGFCore extends TestCase {
                assertNotNull(ps8.getPointedToStreams());
                assertEquals(8, ps8.getPointedToStreams().length);
        }
+       
+       /**
+        * Tests that we can open a problematic file, that initially
+        *  appears to have a negative chunk length
+        */
+       public void DISABLEDtestNegativeChunkLength() throws Exception {
+               filename = dirname + "/NegativeChunkLength.vsd";
+               fs = new POIFSFileSystem(new FileInputStream(filename));
+               
+               HDGFDiagram hdgf = new HDGFDiagram(fs);
+               assertNotNull(hdgf);
+       }
 }
diff --git a/src/scratchpad/testcases/org/apache/poi/hdgf/data/NegativeChunkLength.vsd b/src/scratchpad/testcases/org/apache/poi/hdgf/data/NegativeChunkLength.vsd
new file mode 100644 (file)
index 0000000..58378bd
Binary files /dev/null and b/src/scratchpad/testcases/org/apache/poi/hdgf/data/NegativeChunkLength.vsd differ