diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 9c1529aa5..8c1a63ceb 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,7 @@ + 44593 - Improved handling of short DVRecords 28627 / 44580 - Fix Range.delete() in HWPF 44539 - Support for area references in formulas of rows >= 32768 44536 - Improved support for detecting read-only recommended files diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 367c6b0c7..9213e0184 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + 44593 - Improved handling of short DVRecords 28627 / 44580 - Fix Range.delete() in HWPF 44539 - Support for area references in formulas of rows >= 32768 44536 - Improved support for detecting read-only recommended files diff --git a/src/java/org/apache/poi/hssf/util/HSSFCellRangeAddress.java b/src/java/org/apache/poi/hssf/util/HSSFCellRangeAddress.java index 438f5e596..73804966f 100644 --- a/src/java/org/apache/poi/hssf/util/HSSFCellRangeAddress.java +++ b/src/java/org/apache/poi/hssf/util/HSSFCellRangeAddress.java @@ -18,6 +18,9 @@ package org.apache.poi.hssf.util; import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.POILogFactory; +import org.apache.poi.util.POILogger; + import java.util.ArrayList; /** @@ -38,6 +41,8 @@ import java.util.ArrayList; public class HSSFCellRangeAddress { + private static POILogger logger = POILogFactory.getLogger(HSSFCellRangeAddress.class); + /** * Number of following ADDR structures */ @@ -74,8 +79,19 @@ public class HSSFCellRangeAddress { short first_row = in.readShort(); short first_col = in.readShort(); - short last_row = in.readShort(); - short last_col = in.readShort(); + + short last_row = first_row; + short last_col = first_col; + if(in.remaining() >= 4) { + last_row = in.readShort(); + last_col = in.readShort(); + } else { + // Ran out of data + // For now, issue a warning, finish, and + // hope for the best.... + logger.log(POILogger.WARN, "Ran out of data reading cell references for DVRecord"); + k = this.field_addr_number; + } AddrStructure region = new AddrStructure(first_row, first_col, last_row, last_col); this.field_regions_list.add(region); diff --git a/src/testcases/org/apache/poi/hssf/data/Bug44593.xls b/src/testcases/org/apache/poi/hssf/data/Bug44593.xls new file mode 100644 index 000000000..84d131144 Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/Bug44593.xls differ diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index f9bb362c7..a1c28fa59 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -1127,6 +1127,23 @@ extends TestCase { in.close(); assertFalse(wb.isWriteProtected()); } + + /** + * Some files were having problems with the DVRecord, + * probably due to dropdowns + */ + public void test44593() throws Exception { + FileInputStream in = new FileInputStream(new File(cwd, "Bug44593.xls")); + + // Used to blow up with an IllegalArgumentException + // when creating a DVRecord + // Now won't, but no idea if this means we have + // rubbish in the DVRecord or not... + HSSFWorkbook wb = new HSSFWorkbook(in); + in.close(); + + assertEquals(2, wb.getNumberOfSheets()); + } }