Fix bug #46904, for old biff5/biff7 files where the block chain is terminated incorrectly
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@757873 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ad8f6284e8
commit
d8af6dfdd4
@ -37,6 +37,7 @@
|
||||
|
||||
<!-- Don't forget to update status.xml too! -->
|
||||
<release version="3.5-beta6" date="2009-??-??">
|
||||
<action dev="POI-DEVELOPERS" type="fix">46904 - Fix POIFS issue with duplicate block 0 references on very old BIFF5/BIFF7 files</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">46840 - PageSettingsBlock should include HEADERFOOTER record</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">46885 - update cell type when setting cached formula result in XSSFCell</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">added modifiers for anchor type to XSSFClientAnchor</action>
|
||||
|
@ -34,6 +34,7 @@
|
||||
<!-- Don't forget to update changes.xml too! -->
|
||||
<changes>
|
||||
<release version="3.5-beta6" date="2009-??-??">
|
||||
<action dev="POI-DEVELOPERS" type="fix">46904 - Fix POIFS issue with duplicate block 0 references on very old BIFF5/BIFF7 files</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">46840 - PageSettingsBlock should include HEADERFOOTER record</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">46885 - update cell type when setting cached formula result in XSSFCell</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">added modifiers for anchor type to XSSFClientAnchor</action>
|
||||
|
23
src/java/org/apache/poi/hssf/OldExcelFormatException.java
Normal file
23
src/java/org/apache/poi/hssf/OldExcelFormatException.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -73,6 +73,14 @@ class BlockListImpl
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
@ -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"
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user