// 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
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");
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));
}
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);
+ }
}