Fix for readCompressedUnicode not moaning about length=0, from bug #44643

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@639242 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2008-03-20 11:02:39 +00:00
parent b57f30921b
commit f5b67d0e52
3 changed files with 18 additions and 1 deletions

View File

@ -266,6 +266,9 @@ public class RecordInputStream extends InputStream
}
public String readCompressedUnicode(int length) {
if(length == 0) {
return "";
}
if ((length < 0) || ((remaining() < length) && !isContinueNext())) {
throw new IllegalArgumentException("Illegal length " + length);
}
@ -273,7 +276,7 @@ public class RecordInputStream extends InputStream
StringBuffer buf = new StringBuffer(length);
for (int i=0;i<length;i++) {
if ((remaining() == 0) && (isContinueNext())) {
nextRecord();
nextRecord();
int compressByte = readByte();
if(compressByte != 0) throw new IllegalArgumentException("compressByte in continue records must be 0 while reading compressed unicode");
}

Binary file not shown.

View File

@ -1204,6 +1204,20 @@ extends TestCase {
assertEquals(2, wb.getNumberOfSheets());
}
/**
* Used to give problems due to trying to read a zero
* length string, but that's now properly handled
*/
public void test44643() throws Exception {
FileInputStream in = new FileInputStream(new File(cwd, "44643.xls"));
// Used to blow up with an IllegalArgumentException
HSSFWorkbook wb = new HSSFWorkbook(in);
in.close();
assertEquals(1, wb.getNumberOfSheets());
}
}