]> source.dussan.org Git - poi.git/commitdiff
Fix for BOFRecord from files generated by access etc (bug #42794)
authorNick Burch <nick@apache.org>
Mon, 12 Nov 2007 13:13:25 +0000 (13:13 +0000)
committerNick Burch <nick@apache.org>
Mon, 12 Nov 2007 13:13:25 +0000 (13:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@594102 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/BOFRecord.java
src/testcases/org/apache/poi/hssf/data/bug_42794.mdb [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/data/bug_42794.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java [new file with mode: 0644]

index d2298ea8be378647c79c4ffa6353829d2377600b..f88c1582f6d932520d409d58d12db9d4d78e8e16 100644 (file)
@@ -36,6 +36,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.0.2-FINAL" date="2007-??-??">
+            <action dev="POI-DEVELOPERS" type="fix">42794 - [PATCH] Fix for BOF records from things like Access</action>
             <action dev="POI-DEVELOPERS" type="fix">43648 - Fix for IntPtg and short vs int</action>
             <action dev="POI-DEVELOPERS" type="fix">43751 - [PATCH] - Fix for handling rotated text in HSSFSheet.autoSizeColumn</action>
             <action dev="POI-DEVELOPERS" type="add">Include an Excel text extractor, and put all existing text extractors under a common superclass</action>
index f8c0eb6de82728cf78b70d890546072e2f7e140f..1dc3b60bcd5277947e0d8d157b236cc8c1fd5569 100644 (file)
@@ -33,6 +33,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.0.2-FINAL" date="2007-??-??">
+            <action dev="POI-DEVELOPERS" type="fix">42794 - [PATCH] Fix for BOF records from things like Access</action>
             <action dev="POI-DEVELOPERS" type="fix">43648 - Fix for IntPtg and short vs int</action>
             <action dev="POI-DEVELOPERS" type="fix">43751 - [PATCH] - Fix for handling rotated text in HSSFSheet.autoSizeColumn</action>
             <action dev="POI-DEVELOPERS" type="add">Include an Excel text extractor, and put all existing text extractors under a common superclass</action>
index df532d036e0bdd84282d746b3dc95f89aaab9be8..dd5335a420b2f3894396625ff2f25d95046efae0 100644 (file)
@@ -110,10 +110,21 @@ public class BOFRecord
     {
         field_1_version  = in.readShort();
         field_2_type     = in.readShort();
-        field_3_build    = in.readShort();
-        field_4_year     = in.readShort();
-        field_5_history  = in.readInt();
-        field_6_rversion = in.readInt();
+        
+        // Some external tools don't generate all of
+        //  the remaining fields
+        if (in.remaining() >= 2) {
+            field_3_build = in.readShort();
+        }
+        if (in.remaining() >= 2) {
+            field_4_year = in.readShort();
+        }
+        if (in.remaining() >= 4) {
+            field_5_history  = in.readInt();
+        }
+        if (in.remaining() >= 4) {
+            field_6_rversion = in.readInt();
+        }
     }
 
     /**
diff --git a/src/testcases/org/apache/poi/hssf/data/bug_42794.mdb b/src/testcases/org/apache/poi/hssf/data/bug_42794.mdb
new file mode 100644 (file)
index 0000000..431eff7
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/bug_42794.mdb differ
diff --git a/src/testcases/org/apache/poi/hssf/data/bug_42794.xls b/src/testcases/org/apache/poi/hssf/data/bug_42794.xls
new file mode 100644 (file)
index 0000000..2827d5a
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/bug_42794.xls differ
diff --git a/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java b/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java
new file mode 100644 (file)
index 0000000..63f5cc3
--- /dev/null
@@ -0,0 +1,50 @@
+
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You 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 java.io.File;
+import java.io.FileInputStream;
+
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+
+import junit.framework.TestCase;
+
+public class TestBOFRecord extends TestCase
+{
+    private String _test_file_path;
+    private static final String _test_file_path_property = "HSSF.testdata.path";
+
+    public TestBOFRecord()
+    {
+        super();
+        _test_file_path = System.getProperty( _test_file_path_property ) +
+               File.separator + "bug_42794.xls";
+    }
+
+    public void testBOFRecord() throws Exception {
+       POIFSFileSystem fs = new POIFSFileSystem(
+                       new FileInputStream(_test_file_path)
+       );
+       
+       // This used to throw an error before
+       HSSFWorkbook hssf = new HSSFWorkbook(fs);
+    }
+}