poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 27929] - [PATCH] Opening XLS file with drop down list throws ArrayIndexOutofBoundsException
Date Sat, 03 Jul 2004 11:50:41 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=27929>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=27929

[PATCH] Opening XLS file with drop down list throws ArrayIndexOutofBoundsException





------- Additional Comments From glens@apache.org  2004-07-03 11:50 -------
I applied them as far as I can tell.  Here's a diff with the changes applied to
you can compare for yourself.

Index: java/org/apache/poi/hssf/record/ObjRecord.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/ObjRecord.java,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 ObjRecord.java
--- java/org/apache/poi/hssf/record/ObjRecord.java	22 Feb 2004 11:54:47 -0000
1.1.2.2
+++ java/org/apache/poi/hssf/record/ObjRecord.java	3 Jul 2004 11:47:12 -0000
@@ -98,7 +98,7 @@
             short subRecordSize = LittleEndian.getShort(data, pos + 2);
             Record subRecord = SubRecord.createSubRecord(subRecordSid,
subRecordSize, data, pos + 4);
             subrecords.add(subRecord);
-            pos += 4 + subRecordSize;
+            pos += subRecord.getRecordSize();
         }
 
     }
Index: java/org/apache/poi/hssf/record/SubRecord.java
===================================================================
RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/SubRecord.java,v
retrieving revision 1.1.2.2
diff -u -r1.1.2.2 SubRecord.java
--- java/org/apache/poi/hssf/record/SubRecord.java	22 Feb 2004 11:54:47 -0000
1.1.2.2
+++ java/org/apache/poi/hssf/record/SubRecord.java	3 Jul 2004 11:47:12 -0000
@@ -42,19 +42,28 @@
     {
         Record r = null;
 
+        short adjustedSize = size;
+        if( size < 0) {
+           adjustedSize = 0;
+        } else if( offset + size > data.length) {
+           adjustedSize = (short) (data.length - offset);
+           if( adjustedSize > 4) {
+              adjustedSize -= 4;
+           }
+        }
         switch ( subRecordSid )
         {
             case CommonObjectDataSubRecord.sid:
-                r = new CommonObjectDataSubRecord( subRecordSid, size, data,
offset );
+                r = new CommonObjectDataSubRecord( subRecordSid, adjustedSize,
data, offset );
                 break;
             case GroupMarkerSubRecord.sid:
-                r = new GroupMarkerSubRecord( subRecordSid, size, data, offset );
+                r = new GroupMarkerSubRecord( subRecordSid, adjustedSize, data,
offset );
                 break;
             case EndSubRecord.sid:
-                r = new EndSubRecord( subRecordSid, size, data, offset );
+                r = new EndSubRecord( subRecordSid, adjustedSize, data, offset );
                 break;
             default:
-                r = new UnknownRecord( subRecordSid, size, data, offset );
+                r = new UnknownRecord( subRecordSid, adjustedSize, data, offset );
         }
 
         return r;
Index: testcases/org/apache/poi/hssf/record/TestObjRecord.java
===================================================================
RCS file: testcases/org/apache/poi/hssf/record/TestObjRecord.java
diff -N testcases/org/apache/poi/hssf/record/TestObjRecord.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testcases/org/apache/poi/hssf/record/TestObjRecord.java	3 Jul 2004 11:47:18
-0000
@@ -0,0 +1,94 @@
+/* ====================================================================
+   Copyright 2002-2004   Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record;
+
+import junit.framework.*;
+
+import java.util.List;
+
+/**
+ * Tests for OBJ record.  Test data taken directly
+ * from a real Excel file.
+ *
+ * @author Michael Zalewski (zalewski at optonline.net)
+ */
+public class TestObjRecord extends TestCase
+{
+
+    public TestObjRecord(String name)
+    {
+        super(name);
+    }
+
+
+/*
+   The following is a dump of the OBJ record corresponding to an auto-filter
+   drop-down list. The 3rd subrecord beginning at offset 0x002e (type=0x0013)
+   does not conform to the documentation, because the length field is 0x1fee,
+   which is longer than the entire OBJ record.
+
+   00000000 15 00 12 00 14 00 01 00 01 21 00 00 00 00 3C 13 .........!....<. 
Type=0x15 Len=0x0012 ftCmo
+   00000010 F4 03 00 00 00 00
+                              0C 00 14 00 00 00 00 00 00 00 ................ 
Type=0x0c Len=0x0014 ftSbs
+   00000020 00 00 00 00 01 00 08 00 00 00 10 00 00 00
+                                                      13 00 ................ 
Type=0x13 Len=0x1FEE ftLbsData
+   00000030 EE 1F 00 00 08 00 08 00 01 03 00 00 0A 00 14 00 ................
+   00000040 6C 00
+                  00 00 00 00                               l.....           
Type=0x00 Len=0x0000 ftEnd
+*/
+
+    byte[] dataAutoFilter = new byte[] {
+         // ftCmo
+  	    
(byte)0x15,(byte)0x00,(byte)0x12,(byte)0x00,(byte)0x14,(byte)0x00,(byte)0x01,(byte)0x00
+       
,(byte)0x01,(byte)0x00,(byte)0x01,(byte)0x21,(byte)0x00,(byte)0x00,(byte)0x3c,(byte)0x13
+        ,(byte)0xf4,(byte)0x03,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00
+
+         // ftSbs (currently UnknownSubrecord)
+                                                                            
,(byte)0x0c,(byte)0x00
+       
,(byte)0x14,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00
+       
,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x01,(byte)0x00,(byte)0x08,(byte)0x00
+        ,(byte)0x00,(byte)0x00,(byte)0x10,(byte)0x00,(byte)0x00,(byte)0x00
+
+         // ftLbsData (currently UnknownSubrecord)
+                                                                            
,(byte)0x13,(byte)0x00
+       
,(byte)0xee,(byte)0x1f,(byte)0x00,(byte)0x00,(byte)0x08,(byte)0x00,(byte)0x08,(byte)0x00
+       
,(byte)0x01,(byte)0x03,(byte)0x00,(byte)0x00,(byte)0x0a,(byte)0x00,(byte)0x14,(byte)0x00
+        ,(byte)0x6c,(byte)0x00
+
+         // ftEnd
+                               ,(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00
+    };
+
+    public void testAutoFilter() {
+       ObjRecord or = new ObjRecord( ObjRecord.sid, (short)
dataAutoFilter.length, dataAutoFilter);
+       assertEquals( "Obj record size", 74, or.getRecordSize());
+       List lstSubRecords = or.getSubRecords();
+       assertEquals( "Subrecord count", 4, lstSubRecords.size());
+       Object oSubRecord = lstSubRecords.get( 0);
+       assertEquals(
+             "First subrecord class"
+           , "org.apache.poi.hssf.record.CommonObjectDataSubRecord"
+           , oSubRecord.getClass().getName()
+       );
+       oSubRecord = lstSubRecords.get( 3);
+       assertEquals(
+             "Last subrecord class"
+           , "org.apache.poi.hssf.record.EndSubRecord"
+           , oSubRecord.getClass().getName()
+       );
+    }
+}
\ No newline at end of file
Index: testcases/org/apache/poi/hssf/record/TestSubRecord.java
===================================================================
RCS file: testcases/org/apache/poi/hssf/record/TestSubRecord.java
diff -N testcases/org/apache/poi/hssf/record/TestSubRecord.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testcases/org/apache/poi/hssf/record/TestSubRecord.java	3 Jul 2004 11:47:19
-0000
@@ -0,0 +1,95 @@
+/* ====================================================================
+   Copyright 2002-2004   Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record;
+
+import junit.framework.*;
+
+/**
+ * Tests Subrecord components of an OBJ record.  Test data taken directly
+ * from a real Excel file.
+ *
+ * @author Michael Zalewski (zalewski at optonline.net)
+ */
+public class TestSubRecord extends TestCase
+{
+    /*
+       The following is a dump of the OBJ record corresponding to an auto-filter
+       drop-down list. The 3rd subrecord beginning at offset 0x002e (type=0x0013)
+       does not conform to the documentation, because the length field is 0x1fee,
+       which is longer than the entire OBJ record.
+
+       00000000 15 00 12 00 14 00 01 00 01 21 00 00 00 00 3C 13
.........!....<.  Type=0x15 Len=0x0012 ftCmo
+       00000010 F4 03 00 00 00 00
+                                  0C 00 14 00 00 00 00 00 00 00
................  Type=0x0c Len=0x0014 ftSbs
+       00000020 00 00 00 00 01 00 08 00 00 00 10 00 00 00
+                                                          13 00
................  Type=0x13 Len=0x1FEE ftLbsData
+       00000030 EE 1F 00 00 08 00 08 00 01 03 00 00 0A 00 14 00 ................
+       00000040 6C 00
+                      00 00 00 00                               l.....        
   Type=0x00 Len=0x0000 ftEnd
+    */
+
+    byte[] dataAutoFilter = new byte[]{
+        // ftCmo
+        (byte) 0x15, (byte) 0x00, (byte) 0x12, (byte) 0x00, (byte) 0x14, (byte)
0x00, (byte) 0x01, (byte) 0x00
+        , (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x21, (byte) 0x00,
(byte) 0x00, (byte) 0x3c, (byte) 0x13
+        , (byte) 0xf4, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00
+
+        // ftSbs (currently UnknownSubrecord)
+        , (byte) 0x0c, (byte) 0x00
+        , (byte) 0x14, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x00
+        , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
(byte) 0x00, (byte) 0x08, (byte) 0x00
+        , (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x00, (byte) 0x00,
(byte) 0x00
+
+        // ftLbsData (currently UnknownSubrecord)
+        , (byte) 0x13, (byte) 0x00
+        , (byte) 0xee, (byte) 0x1f, (byte) 0x00, (byte) 0x00, (byte) 0x08,
(byte) 0x00, (byte) 0x08, (byte) 0x00
+        , (byte) 0x01, (byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x0a,
(byte) 0x00, (byte) 0x14, (byte) 0x00
+        , (byte) 0x6c, (byte) 0x00
+
+        // ftEnd
+        , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
+    };
+
+    public TestSubRecord( String name )
+    {
+        super( name );
+    }
+
+    public void testParseCmo()
+    {
+        Record r = SubRecord.createSubRecord( (short) 0x0015, (short) 0x0012,
dataAutoFilter, 0x0000 );
+        assertEquals( "ftCmo is 22 bytes", 22, r.getRecordSize() );
+        assertEquals( "ftCmo is a CommonObjectDataSubRecord"
+                , "org.apache.poi.hssf.record.CommonObjectDataSubRecord"
+                , r.getClass().getName() );
+    }
+
+    public void testParseAutoFilterLbsData()
+    {
+        Record r = SubRecord.createSubRecord( (short) 0x0013, (short) 0x1fee,
dataAutoFilter, 0x0032 );
+        assertEquals( "ftLbsData is 20 bytes", 20, r.getRecordSize() );
+    }
+
+    public void testParseEnd()
+    {
+        Record r = SubRecord.createSubRecord( (short) 0x0000, (short) 0x0000,
dataAutoFilter, 0x0046 );
+        assertEquals( "ftEnd is 4 bytes", 4, r.getRecordSize() );
+        assertEquals( "ftEnd is a EndSubRecord"
+                , "org.apache.poi.hssf.record.EndSubRecord"
+                , r.getClass().getName() );
+    }
+}
\ No newline at end of file

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org


Mime
View raw message