From: Nick Burch Date: Wed, 25 Nov 2009 12:11:04 +0000 (+0000) Subject: Fix bug #48180 - short chart records skipping some unused fields X-Git-Tag: REL_3_6~28 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=76ae29d587c94767dab8002ef6dc40ecb5688ae7;p=poi.git Fix bug #48180 - short chart records skipping some unused fields git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@884065 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 10e006b4e3..5369cda040 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 48180 - be more forgiving of short chart records, which skip some unused fields 48274 - fix erronious wrapping of byte colours in HSSFPalette.findSimilarColor 48269 - fix fetching of error codes from XSSF formula cells 48229 - fixed javadoc for HSSFSheet.setColumnWidth and XSSFSheet setColumnWidth diff --git a/src/java/org/apache/poi/hssf/record/chart/CatLabRecord.java b/src/java/org/apache/poi/hssf/record/chart/CatLabRecord.java index 84eb4b063f..058f13cd66 100644 --- a/src/java/org/apache/poi/hssf/record/chart/CatLabRecord.java +++ b/src/java/org/apache/poi/hssf/record/chart/CatLabRecord.java @@ -35,7 +35,7 @@ public final class CatLabRecord extends StandardRecord { private short wOffset; private short at; private short grbit; - private short unused; + private Short unused; public CatLabRecord(RecordInputStream in) { rt = in.readShort(); @@ -43,12 +43,18 @@ public final class CatLabRecord extends StandardRecord { wOffset = in.readShort(); at = in.readShort(); grbit = in.readShort(); - unused = in.readShort(); + + // Often, but not always has an unused short at the end + if(in.available() == 0) { + unused = null; + } else { + unused = in.readShort(); + } } @Override protected int getDataSize() { - return 2 + 2 + 2 + 2 + 2 + 2; + return 2 + 2 + 2 + 2 + 2 + (unused==null? 0:2); } @Override @@ -58,13 +64,13 @@ public final class CatLabRecord extends StandardRecord { @Override public void serialize(LittleEndianOutput out) { - out.writeShort(rt); out.writeShort(grbitFrt); out.writeShort(wOffset); out.writeShort(at); out.writeShort(grbit); - out.writeShort(unused); + if(unused != null) + out.writeShort(unused); } @Override diff --git a/src/java/org/apache/poi/hssf/record/chart/ChartEndBlockRecord.java b/src/java/org/apache/poi/hssf/record/chart/ChartEndBlockRecord.java index f69a020c72..ac823b2b12 100644 --- a/src/java/org/apache/poi/hssf/record/chart/ChartEndBlockRecord.java +++ b/src/java/org/apache/poi/hssf/record/chart/ChartEndBlockRecord.java @@ -40,13 +40,18 @@ public final class ChartEndBlockRecord extends StandardRecord { grbitFrt = in.readShort(); iObjectKind = in.readShort(); - unused = new byte[6]; - in.readFully(unused); + // Often, but not always has 6 unused bytes at the end + if(in.available() == 0) { + unused = new byte[0]; + } else { + unused = new byte[6]; + in.readFully(unused); + } } @Override protected int getDataSize() { - return 2 + 2 + 2 + 6; + return 2 + 2 + 2 + unused.length; } @Override diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index e55dd2d05d..5e15be8405 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -1509,4 +1509,17 @@ public final class TestBugs extends BaseTestBugzillaIssues { assertEquals(32766, cell2.getStringCellValue().length()); } + /** + * Short records on certain sheets with charts in them + */ + public void test48180() { + HSSFWorkbook wb = openSample("48180.xls"); + + HSSFSheet s = wb.getSheetAt(0); + HSSFCell cell1 = s.getRow(0).getCell(0); + assertEquals("test ", cell1.getStringCellValue().toString()); + + HSSFCell cell2 = s.getRow(0).getCell(1); + assertEquals(1.0, cell2.getNumericCellValue()); + } } diff --git a/test-data/spreadsheet/48180.xls b/test-data/spreadsheet/48180.xls new file mode 100644 index 0000000000..be72749be3 Binary files /dev/null and b/test-data/spreadsheet/48180.xls differ