From 76ae29d587c94767dab8002ef6dc40ecb5688ae7 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 25 Nov 2009 12:11:04 +0000 Subject: [PATCH] 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 --- src/documentation/content/xdocs/status.xml | 1 + .../poi/hssf/record/chart/CatLabRecord.java | 16 +++++++++++----- .../hssf/record/chart/ChartEndBlockRecord.java | 11 ++++++++--- .../org/apache/poi/hssf/usermodel/TestBugs.java | 13 +++++++++++++ test-data/spreadsheet/48180.xls | Bin 0 -> 20992 bytes 5 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 test-data/spreadsheet/48180.xls 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 0000000000000000000000000000000000000000..be72749be3ca3a6c9bb18f877b7f16a1cabafe23 GIT binary patch literal 20992 zcmeHP4RlmRmaf<7Kqo}$0PZA+(8Rw0l7vKsU<@I|3}ht4Bt*A^#L#J)*pSYq+i9?I z5=L>^S!Wj!oIwMkqYe%nb&dIta??q?!9&Ity{P1Eh2vomG=aB`@K-Q}OM=aDJTOHr#~ z>o1cm@EE1I1&kavmO>nor6|`Qdil%wZ#N#jXdW^G$*saC+JslEz|)84NYglB z(df5IhT+gt!lU^*X0oUecZoIl*9bY*iAADCtduel5)jR(w+zBG8{<m1pQKJkuqSQnuAa=wPLNMzn$IJ3LiSwe4 ziJlYT6X84V-&8vX7~G#e(MlxV4`rE!QbPn|`3p(&KN3C*5$k2(hub$BmKiPT+-*&b zEsc7YhOQSmDpFjRWnikLfvE-@YZpcsPz*-psDuj|S2wR{Yo2VK1V=*1&AKA%@@p=? zJg;He4a>4sW7)LH)~N{U*sc`_{q@!ErrTqYvY;5&rb5cei{*nhSzQeYvf{DgxEZLk z#dLvn)<99FJCtNbb6K_oESq+N0mzz}1-TlsOBygrj+lmjAT`rXcbJK$J7Os2iEG5% z*uiuSV#kxBnTDJ?!O1ld{)G(JgoElCNw;${rcv6VFCIQ^0QfZnz^4xYPdN+zki{zO z9Z6w6(>q4V=eQ25e2(uJEuW%8$mfKPRJ!S1zPY)3o1{fIcS9nT}%MZwCjC^&KiaD*i0?Z_*ISh;e$ zc=+Lm1rS8Rb^r?SAM$pY0V@D40L$zb%bgKa#@2X;jJX>Tf!Fd#iLg|&%Iyx!dH|g}#rFL$a_E zCE)f492(BWqr_}9nbORC`LTVlg0NU^;(F|~z1lOD60h?Adn~ zZ98>U>VprA78YdfzJpiuxGc}%*>VK^Je`SnZNDpgkbN6~L;8}Z$M3QM_RPIcXsk1{ zf82M&2Q_HFd8fnrAM+P&d-0cxwygpl?URjs8*&m4_C~t-=_j-f@FX2^m?xpmZe^i4 z_H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