From d601a0b4b7f052ea0d6de4867b63794a8cf9f483 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Fri, 22 Feb 2008 11:40:00 +0000 Subject: [PATCH] Bug #44471 - Crystal Reports generates files with short StyleRecords, which isn't allowed in the spec. Work around this git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@630164 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 1 + src/documentation/content/xdocs/status.xml | 1 + .../org/apache/poi/hssf/record/StyleRecord.java | 17 +++++++++++------ .../org/apache/poi/hssf/usermodel/TestBugs.java | 11 ++++------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 285dcdea5..ae32d44f8 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,7 @@ + 44471 - Crystal Reports generates files with short StyleRecords, which isn't allowed in the spec. Work around this 44450 - Support for Lookup, HLookup and VLookup functions 44449 - Avoid getting confused when two sheets have shared formulas for the same areas, and when the shared formula is set incorrectly 44366 - InputStreams passed to POIFSFileSystem are now automatically closed. A warning is generated for people who might've relied on them not being closed before, and a wrapper to restore the old behaviour is supplied diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 18229083e..ec41cc533 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,7 @@ + 44471 - Crystal Reports generates files with short StyleRecords, which isn't allowed in the spec. Work around this 44450 - Support for Lookup, HLookup and VLookup functions 44449 - Avoid getting confused when two sheets have shared formulas for the same areas, and when the shared formula is set incorrectly 44366 - InputStreams passed to POIFSFileSystem are now automatically closed. A warning is generated for people who might've relied on them not being closed before, and a wrapper to restore the old behaviour is supplied diff --git a/src/java/org/apache/poi/hssf/record/StyleRecord.java b/src/java/org/apache/poi/hssf/record/StyleRecord.java index 9f45e3adf..65ca23cf3 100644 --- a/src/java/org/apache/poi/hssf/record/StyleRecord.java +++ b/src/java/org/apache/poi/hssf/record/StyleRecord.java @@ -88,13 +88,18 @@ public class StyleRecord else if (getType() == STYLE_USER_DEFINED) { field_2_name_length = in.readShort(); - field_3_string_options = in.readByte(); - byte[] string = in.readRemainder(); - if (fHighByte.isSet(field_3_string_options)) { - field_4_name= StringUtil.getFromUnicodeBE(string, 0, field_2_name_length); - }else { - field_4_name=StringUtil.getFromCompressedUnicode(string, 0, field_2_name_length); + // Some files from Crystal Reports lack + // the remaining fields, which is naughty + if(in.remaining() > 0) { + field_3_string_options = in.readByte(); + + byte[] string = in.readRemainder(); + if (fHighByte.isSet(field_3_string_options)) { + field_4_name= StringUtil.getFromUnicodeBE(string, 0, field_2_name_length); + } else { + field_4_name=StringUtil.getFromCompressedUnicode(string, 0, field_2_name_length); + } } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index dc38824d3..04c729b3b 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -1091,17 +1091,14 @@ extends TestCase { } /** - * Date: Tue, 19 Feb 2008 05:03:47 -0800 (PST) - * From: Setya - * Subject: Exception when parsing excel file + * Crystal reports generates files with short + * StyleRecords, which is against the spec */ - public void BROKENtest20080219() throws Exception { + public void test44471() throws Exception { FileInputStream in = new FileInputStream(new File(cwd, "OddStyleRecord.xls")); - // Blows up with an ArrayIndexOutOfBounds + // Used to blow up with an ArrayIndexOutOfBounds // when creating a StyleRecord - // However, our code matches the latest Microsoft - // docs, so no idea what's wrong HSSFWorkbook wb = new HSSFWorkbook(in); in.close();