Add in a (disabled) test for bug #43670 (not yet fixed)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@589417 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2007-10-28 20:56:34 +00:00
parent a1ed3f51e4
commit 75e57d9414
4 changed files with 24 additions and 3 deletions

View File

@ -107,6 +107,12 @@ public class ChunkFactory {
// Create the header // Create the header
ChunkHeader header = ChunkHeader header =
ChunkHeader.createChunkHeader(version, data, offset); 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(); int endOfDataPos = offset + header.getLength() + header.getSizeInBytes();
// Check we have enough data, and tweak the header size // Check we have enough data, and tweak the header size

View File

@ -45,6 +45,7 @@ public abstract class ChunkHeader {
ch.length = (int)LittleEndian.getUInt(data, offset + 12); ch.length = (int)LittleEndian.getUInt(data, offset + 12);
ch.unknown2 = LittleEndian.getShort(data, offset + 16); ch.unknown2 = LittleEndian.getShort(data, offset + 16);
ch.unknown3 = (short)LittleEndian.getUnsignedByte(data, offset + 18); ch.unknown3 = (short)LittleEndian.getUnsignedByte(data, offset + 18);
return ch; return ch;
} else if(documentVersion == 5) { } else if(documentVersion == 5) {
throw new RuntimeException("TODO"); throw new RuntimeException("TODO");

View File

@ -25,11 +25,13 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import junit.framework.TestCase; import junit.framework.TestCase;
public class TestHDGFCore extends TestCase { public class TestHDGFCore extends TestCase {
POIFSFileSystem fs; private POIFSFileSystem fs;
private String dirname;
private String filename;
protected void setUp() throws Exception { protected void setUp() throws Exception {
String dirname = System.getProperty("HDGF.testdata.path"); dirname = System.getProperty("HDGF.testdata.path");
String filename = dirname + "/Test_Visio-Some_Random_Text.vsd"; filename = dirname + "/Test_Visio-Some_Random_Text.vsd";
fs = new POIFSFileSystem(new FileInputStream(filename)); fs = new POIFSFileSystem(new FileInputStream(filename));
} }
@ -59,4 +61,16 @@ public class TestHDGFCore extends TestCase {
assertNotNull(ps8.getPointedToStreams()); assertNotNull(ps8.getPointedToStreams());
assertEquals(8, ps8.getPointedToStreams().length); 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);
}
} }