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:
parent
b57f30921b
commit
f5b67d0e52
@ -266,6 +266,9 @@ public class RecordInputStream extends InputStream
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String readCompressedUnicode(int length) {
|
public String readCompressedUnicode(int length) {
|
||||||
|
if(length == 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
if ((length < 0) || ((remaining() < length) && !isContinueNext())) {
|
if ((length < 0) || ((remaining() < length) && !isContinueNext())) {
|
||||||
throw new IllegalArgumentException("Illegal length " + length);
|
throw new IllegalArgumentException("Illegal length " + length);
|
||||||
}
|
}
|
||||||
@ -273,7 +276,7 @@ public class RecordInputStream extends InputStream
|
|||||||
StringBuffer buf = new StringBuffer(length);
|
StringBuffer buf = new StringBuffer(length);
|
||||||
for (int i=0;i<length;i++) {
|
for (int i=0;i<length;i++) {
|
||||||
if ((remaining() == 0) && (isContinueNext())) {
|
if ((remaining() == 0) && (isContinueNext())) {
|
||||||
nextRecord();
|
nextRecord();
|
||||||
int compressByte = readByte();
|
int compressByte = readByte();
|
||||||
if(compressByte != 0) throw new IllegalArgumentException("compressByte in continue records must be 0 while reading compressed unicode");
|
if(compressByte != 0) throw new IllegalArgumentException("compressByte in continue records must be 0 while reading compressed unicode");
|
||||||
}
|
}
|
||||||
|
BIN
src/testcases/org/apache/poi/hssf/data/44643.xls
Normal file
BIN
src/testcases/org/apache/poi/hssf/data/44643.xls
Normal file
Binary file not shown.
@ -1204,6 +1204,20 @@ extends TestCase {
|
|||||||
|
|
||||||
assertEquals(2, wb.getNumberOfSheets());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user