From: Nick Burch Date: Mon, 12 Nov 2007 13:13:25 +0000 (+0000) Subject: Fix for BOFRecord from files generated by access etc (bug #42794) X-Git-Tag: REL_3_0_2_BETA1~10 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f9ebc1ae74d290098127f945b960556d2a64c0f9;p=poi.git Fix for BOFRecord from files generated by access etc (bug #42794) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@594102 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index d2298ea8be..f88c1582f6 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,7 @@ + 42794 - [PATCH] Fix for BOF records from things like Access 43648 - Fix for IntPtg and short vs int 43751 - [PATCH] - Fix for handling rotated text in HSSFSheet.autoSizeColumn Include an Excel text extractor, and put all existing text extractors under a common superclass diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index f8c0eb6de8..1dc3b60bcd 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + 42794 - [PATCH] Fix for BOF records from things like Access 43648 - Fix for IntPtg and short vs int 43751 - [PATCH] - Fix for handling rotated text in HSSFSheet.autoSizeColumn Include an Excel text extractor, and put all existing text extractors under a common superclass diff --git a/src/java/org/apache/poi/hssf/record/BOFRecord.java b/src/java/org/apache/poi/hssf/record/BOFRecord.java index df532d036e..dd5335a420 100644 --- a/src/java/org/apache/poi/hssf/record/BOFRecord.java +++ b/src/java/org/apache/poi/hssf/record/BOFRecord.java @@ -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 index 0000000000..431eff734e 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 index 0000000000..2827d5ac6d 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 index 0000000000..63f5cc317e --- /dev/null +++ b/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java @@ -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); + } +}