]> source.dussan.org Git - poi.git/commitdiff
Fix bug #48180 - short chart records skipping some unused fields
authorNick Burch <nick@apache.org>
Wed, 25 Nov 2009 12:11:04 +0000 (12:11 +0000)
committerNick Burch <nick@apache.org>
Wed, 25 Nov 2009 12:11:04 +0000 (12:11 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@884065 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/chart/CatLabRecord.java
src/java/org/apache/poi/hssf/record/chart/ChartEndBlockRecord.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/48180.xls [new file with mode: 0644]

index 10e006b4e3d3559da0c79f50691be8c5c90e8167..5369cda040ff771ebd698f22fdcfc0cd33ed10f5 100644 (file)
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.6-beta1" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">48180 - be more forgiving of short chart records, which skip some unused fields</action>
            <action dev="POI-DEVELOPERS" type="fix">48274 - fix erronious wrapping of byte colours in HSSFPalette.findSimilarColor</action>
            <action dev="POI-DEVELOPERS" type="fix">48269 - fix fetching of error codes from XSSF formula cells</action>
            <action dev="POI-DEVELOPERS" type="fix">48229 - fixed javadoc for  HSSFSheet.setColumnWidth and XSSFSheet setColumnWidth </action>
index 84eb4b063f743bd4838b111879abe3976ccf66dc..058f13cd66a9e0356b547d2ff7ebc9bda4f6b8da 100644 (file)
@@ -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
index f69a020c72f2144be4bf73ed72d4b668da9eea55..ac823b2b1282ed8418658f5c29d9fdc51f16f9f9 100644 (file)
@@ -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
index e55dd2d05d99702d88127a33be6d658f479097a7..5e15be84056f863e22ee8d977faf5d67c0888f69 100644 (file)
@@ -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 (file)
index 0000000..be72749
Binary files /dev/null and b/test-data/spreadsheet/48180.xls differ