aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases
diff options
context:
space:
mode:
authorJosh Micich <josh@apache.org>2009-01-29 01:57:22 +0000
committerJosh Micich <josh@apache.org>2009-01-29 01:57:22 +0000
commit7d01fc135e420d5eb4030e52557bb6b0d9a09335 (patch)
treeb7af4039e45b0808d662d1aa9060f8698614cf0a /src/testcases
parent7aa965d079344d296edb339a77bbf2f9a6ce1fb8 (diff)
downloadpoi-7d01fc135e420d5eb4030e52557bb6b0d9a09335.tar.gz
poi-7d01fc135e420d5eb4030e52557bb6b0d9a09335.zip
Fix for bug 46545 - ObjRecord should ignore excessive padding written by previous POI versions
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@738709 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases')
-rw-r--r--src/testcases/org/apache/poi/hssf/record/TestSubRecord.java69
1 files changed, 59 insertions, 10 deletions
diff --git a/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java b/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java
index 9d0edd1c14..926f243975 100644
--- a/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java
+++ b/src/testcases/org/apache/poi/hssf/record/TestSubRecord.java
@@ -25,6 +25,7 @@ import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.util.HexRead;
+import org.apache.poi.util.LittleEndian;
/**
* Tests Subrecord components of an OBJ record. Test data taken directly
@@ -85,21 +86,21 @@ public final class TestSubRecord extends TestCase {
public void testReadManualComboWithFormula() {
byte[] data = HexRead.readFromString(""
- + "5D 00 66 00 "
- + "15 00 12 00 14 00 02 00 11 20 00 00 00 00 "
- + "20 44 C6 04 00 00 00 00 0C 00 14 00 04 F0 C6 04 "
- + "00 00 00 00 00 00 01 00 06 00 00 00 10 00 00 00 "
- + "0E 00 0C 00 05 00 80 44 C6 04 24 09 00 02 00 02 "
- + "13 00 DE 1F 10 00 09 00 80 44 C6 04 25 0A 00 0F "
- + "00 02 00 02 00 02 06 00 03 00 08 00 00 00 00 00 "
- + "08 00 00 00 00 00 00 00 " // TODO sometimes last byte is non-zero
- );
+ + "5D 00 66 00 "
+ + "15 00 12 00 14 00 02 00 11 20 00 00 00 00 "
+ + "20 44 C6 04 00 00 00 00 0C 00 14 00 04 F0 C6 04 "
+ + "00 00 00 00 00 00 01 00 06 00 00 00 10 00 00 00 "
+ + "0E 00 0C 00 05 00 80 44 C6 04 24 09 00 02 00 02 "
+ + "13 00 DE 1F 10 00 09 00 80 44 C6 04 25 0A 00 0F "
+ + "00 02 00 02 00 02 06 00 03 00 08 00 00 00 00 00 "
+ + "08 00 00 00 00 00 00 00 " // TODO sometimes last byte is non-zero
+ );
RecordInputStream in = TestcaseRecordInputStream.create(data);
ObjRecord or = new ObjRecord(in);
byte[] data2 = or.serialize();
if (data2.length == 8228) {
- throw new AssertionFailedError("Identified bug XXXXX");
+ throw new AssertionFailedError("Identified bug 45778");
}
assertEquals("Encoded length", data.length, data2.length);
for (int i = 0; i < data.length; i++) {
@@ -109,4 +110,52 @@ public final class TestSubRecord extends TestCase {
}
assertTrue(Arrays.equals(data, data2));
}
+
+ /**
+ * Some versions of POI (e.g. 3.1 - prior to svn r707450 / bug 45778) interpreted the ftLbs
+ * subrecord second short (0x1FEE) as a length, and hence read lots of extra padding. This
+ * buffer-overrun in {@link RecordInputStream} happened silently due to problems later fixed
+ * in svn 707778. When the ObjRecord is written, the extra padding is written too, making the
+ * record 8224 bytes long instead of 70.
+ * (An aside: It seems more than a coincidence that this problem creates a record of exactly
+ * {@link RecordInputStream#MAX_RECORD_DATA_SIZE} but not enough is understood about
+ * subrecords to explain this.)<br/>
+ *
+ * Excel reads files with this excessive padding OK. It also truncates the over-sized
+ * ObjRecord back to the proper size. POI should do the same.
+ */
+ public void testWayTooMuchPadding_bug46545() {
+ byte[] data = HexRead.readFromString(""
+ + "15 00 12 00 14 00 13 00 01 21 00 00 00"
+ + "00 98 0B 5B 09 00 00 00 00 0C 00 14 00 00 00 00 00 00 00 00"
+ + "00 00 00 01 00 01 00 00 00 10 00 00 00 "
+ // ftLbs
+ + "13 00 EE 1F 00 00 "
+ + "01 00 00 00 01 06 00 00 02 00 08 00 75 00 "
+ // ftEnd
+ + "00 00 00 00"
+ );
+ final int LBS_START_POS = 0x002E;
+ final int WRONG_LBS_SIZE = 0x1FEE;
+ assertEquals(0x0013, LittleEndian.getShort(data, LBS_START_POS+0));
+ assertEquals(WRONG_LBS_SIZE, LittleEndian.getShort(data, LBS_START_POS+2));
+ int wrongTotalSize = LBS_START_POS + 4 + WRONG_LBS_SIZE;
+ byte[] wrongData = new byte[wrongTotalSize];
+ System.arraycopy(data, 0, wrongData, 0, data.length);
+ // wrongData has the ObjRecord data as would have been written by v3.1
+
+ RecordInputStream in = TestcaseRecordInputStream.create(ObjRecord.sid, wrongData);
+ ObjRecord or;
+ try {
+ or = new ObjRecord(in);
+ } catch (RecordFormatException e) {
+ if (e.getMessage().startsWith("Leftover 8154 bytes in subrecord data")) {
+ throw new AssertionFailedError("Identified bug 46545");
+ }
+ throw e;
+ }
+ // make sure POI properly truncates the ObjRecord data
+ byte[] data2 = or.serialize();
+ TestcaseRecordInputStream.confirmRecordEncoding(ObjRecord.sid, data, data2);
+ }
}