diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 0cb62592cb..577e2c1d12 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 46904 - Fix POIFS issue with duplicate block 0 references on very old BIFF5/BIFF7 files 46840 - PageSettingsBlock should include HEADERFOOTER record 46885 - update cell type when setting cached formula result in XSSFCell added modifiers for anchor type to XSSFClientAnchor diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index bef81975fa..af309e998f 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 46904 - Fix POIFS issue with duplicate block 0 references on very old BIFF5/BIFF7 files 46840 - PageSettingsBlock should include HEADERFOOTER record 46885 - update cell type when setting cached formula result in XSSFCell added modifiers for anchor type to XSSFClientAnchor diff --git a/src/java/org/apache/poi/hssf/OldExcelFormatException.java b/src/java/org/apache/poi/hssf/OldExcelFormatException.java new file mode 100644 index 0000000000..5b8e5e4c41 --- /dev/null +++ b/src/java/org/apache/poi/hssf/OldExcelFormatException.java @@ -0,0 +1,23 @@ +/* ==================================================================== + 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; + +public class OldExcelFormatException extends IllegalArgumentException { + public OldExcelFormatException(String s) { + super(s); + } +} \ No newline at end of file diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 3f6d525edc..1964417366 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -34,6 +34,7 @@ import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherBitmapBlip; import org.apache.poi.ddf.EscherBlipRecord; import org.apache.poi.ddf.EscherRecord; +import org.apache.poi.hssf.OldExcelFormatException; import org.apache.poi.hssf.model.HSSFFormulaParser; import org.apache.poi.hssf.model.RecordStream; import org.apache.poi.hssf.model.Sheet; @@ -227,7 +228,7 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm // check for previous version of file format try { directory.getEntry("Book"); - throw new IllegalArgumentException("The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. " + throw new OldExcelFormatException("The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. " + "POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)"); } catch (FileNotFoundException e) { // fall through diff --git a/src/java/org/apache/poi/poifs/storage/BlockAllocationTableReader.java b/src/java/org/apache/poi/poifs/storage/BlockAllocationTableReader.java index 1016db9c46..19873c08fd 100644 --- a/src/java/org/apache/poi/poifs/storage/BlockAllocationTableReader.java +++ b/src/java/org/apache/poi/poifs/storage/BlockAllocationTableReader.java @@ -200,6 +200,10 @@ public class BlockAllocationTableReader // Special case where things are in the wrong order System.err.println("Warning, header block comes after data blocks in POIFS block listing"); currentBlock = POIFSConstants.END_OF_CHAIN; + } else if(currentBlock == 0) { + // Special case where the termination isn't done right + System.err.println("Warning, incorrectly terminated data blocks in POIFS block listing (should end at -2, ended at 0)"); + currentBlock = POIFSConstants.END_OF_CHAIN; } else { // Ripple up throw e; diff --git a/src/java/org/apache/poi/poifs/storage/BlockListImpl.java b/src/java/org/apache/poi/poifs/storage/BlockListImpl.java index f315b5d515..a5472d3530 100644 --- a/src/java/org/apache/poi/poifs/storage/BlockListImpl.java +++ b/src/java/org/apache/poi/poifs/storage/BlockListImpl.java @@ -72,6 +72,14 @@ class BlockListImpl _blocks[ index ] = null; } } + + /** + * Unit testing method. Gets, without sanity checks or + * removing. + */ + protected ListManagedBlock get(final int index) throws IOException { + return _blocks[index]; + } /** * remove and return the specified block from the list diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 4130c15970..af1ec26aa0 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -25,6 +25,7 @@ import junit.framework.AssertionFailedError; import junit.framework.TestCase; import org.apache.poi.hssf.HSSFTestDataSamples; +import org.apache.poi.hssf.OldExcelFormatException; import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.record.CellValueRecordInterface; import org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord; @@ -1669,8 +1670,16 @@ public final class TestBugs extends TestCase { /** * java.io.IOException: block[ 0 ] already removed + * (is an excel 95 file though) */ - public void BROKENtest46904() throws IOException { - HSSFWorkbook wb = openSample("46904.xls"); + public void test46904() throws IOException { + try { + HSSFWorkbook wb = openSample("46904.xls"); + fail(); + } catch(OldExcelFormatException e) { + assertTrue(e.getMessage().startsWith( + "The supplied spreadsheet seems to be Excel" + )); + } } }