From: Josh Micich Date: Tue, 31 Mar 2009 21:12:47 +0000 (+0000) Subject: Fix for 46918 - Allow shorter format for ExtendedPivotTableViewFieldsRecord(SXVDEX... X-Git-Tag: REL_3_5_BETA6~78 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7dcd9c006bff0ab8e5904145ca310b6a99670895;p=poi.git Fix for 46918 - Allow shorter format for ExtendedPivotTableViewFieldsRecord(SXVDEX) record git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@760646 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index cc2a0ce286..52f96225aa 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 46918 - Fixed ExtendedPivotTableViewFieldsRecord(SXVDEX) to allow shorter format 46898 - Fixed formula evaluator to not cache intermediate circular-reference error results 46917 - Fixed PageItemRecord(SXPI) to allow multiple field infos 46904 - Fix POIFS issue with duplicate block 0 references on very old BIFF5/BIFF7 files diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index cb3c8ffa38..e6cc63338a 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 46918 - Fixed ExtendedPivotTableViewFieldsRecord(SXVDEX) to allow shorter format 46898 - Fixed formula evaluator to not cache intermediate circular-reference error results 46917 - Fixed PageItemRecord(SXPI) to allow multiple field infos 46904 - Fix POIFS issue with duplicate block 0 references on very old BIFF5/BIFF7 files diff --git a/src/java/org/apache/poi/hssf/record/pivottable/ExtendedPivotTableViewFieldsRecord.java b/src/java/org/apache/poi/hssf/record/pivottable/ExtendedPivotTableViewFieldsRecord.java index 92911a1f2b..70c9ebcc13 100644 --- a/src/java/org/apache/poi/hssf/record/pivottable/ExtendedPivotTableViewFieldsRecord.java +++ b/src/java/org/apache/poi/hssf/record/pivottable/ExtendedPivotTableViewFieldsRecord.java @@ -17,6 +17,7 @@ package org.apache.poi.hssf.record.pivottable; +import org.apache.poi.hssf.record.RecordFormatException; import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.StandardRecord; import org.apache.poi.util.HexDump; @@ -31,7 +32,7 @@ import org.apache.poi.util.StringUtil; public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord { public static final short sid = 0x0100; - /** the value of the subname length when the {@link #_subName} is not present */ + /** the value of the subname length when the {@link #_subtotalName} is not present */ private static final int STRING_NOT_PRESENT_LEN = 0xFFFF; private int _grbit1; @@ -41,7 +42,8 @@ public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord { private int _isxdiShow; private int _reserved1; private int _reserved2; - private String _subName; + /** custom sub-total name */ + private String _subtotalName; public ExtendedPivotTableViewFieldsRecord(RecordInputStream in) { @@ -50,11 +52,26 @@ public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord { _citmShow = in.readUByte(); _isxdiSort = in.readUShort(); _isxdiShow = in.readUShort(); + // This record seems to have different valid encodings + switch (in.remaining()) { + case 0: + // as per "Microsoft Excel Developer's Kit" book + // older version of SXVDEX - doesn't seem to have a sub-total name + _reserved1 = 0; + _reserved2 = 0; + _subtotalName = null; + return; + case 10: + // as per "MICROSOFT OFFICE EXCEL 97-2007 BINARY FILE FORMAT SPECIFICATION" pdf + break; + default: + throw new RecordFormatException("Unexpected remaining size (" + in.remaining() + ")"); + } int cchSubName = in.readUShort(); _reserved1 = in.readInt(); _reserved2 = in.readInt(); if (cchSubName != STRING_NOT_PRESENT_LEN) { - _subName = in.readUnicodeLEString(cchSubName); + _subtotalName = in.readUnicodeLEString(cchSubName); } } @@ -67,16 +84,16 @@ public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord { out.writeShort(_isxdiSort); out.writeShort(_isxdiShow); - if (_subName == null) { + if (_subtotalName == null) { out.writeShort(STRING_NOT_PRESENT_LEN); } else { - out.writeShort(_subName.length()); + out.writeShort(_subtotalName.length()); } out.writeInt(_reserved1); out.writeInt(_reserved2); - if (_subName != null) { - StringUtil.putUnicodeLE(_subName, out); + if (_subtotalName != null) { + StringUtil.putUnicodeLE(_subtotalName, out); } } @@ -84,7 +101,7 @@ public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord { protected int getDataSize() { return 4 + 1 + 1 + 2 + 2 + 2 + 4 + 4 + - (_subName == null ? 0 : (2*_subName.length())); // in unicode + (_subtotalName == null ? 0 : (2*_subtotalName.length())); // in unicode } @Override @@ -103,7 +120,7 @@ public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord { buffer.append(" .citmShow =").append(HexDump.byteToHex(_citmShow)).append("\n"); buffer.append(" .isxdiSort =").append(HexDump.shortToHex(_isxdiSort)).append("\n"); buffer.append(" .isxdiShow =").append(HexDump.shortToHex(_isxdiShow)).append("\n"); - buffer.append(" .subName =").append(_subName).append("\n"); + buffer.append(" .subtotalName =").append(_subtotalName).append("\n"); buffer.append("[/SXVDEX]\n"); return buffer.toString(); } diff --git a/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java b/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java index 7ba15d5c26..945528dd2d 100644 --- a/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java @@ -51,4 +51,26 @@ public final class TestExtendedPivotTableViewFieldsRecord extends TestCase { assertEquals(data.length, rec.getRecordSize()); } + + public void testOlderFormat_bug46918() { + // There are 10 SXVDEX records in the file (not uploaded) that originated bugzilla 46918 + // They all had the following hex encoding: + byte data[] = HexRead.readFromString("00 01 0A 00 1E 14 00 0A FF FF FF FF 00 00"); + + RecordInputStream in = TestcaseRecordInputStream.create(data); + ExtendedPivotTableViewFieldsRecord rec; + try { + rec = new ExtendedPivotTableViewFieldsRecord(in); + } catch (RecordFormatException e) { + if (e.getMessage().equals("Not enough data (0) to read requested (2) bytes")) { + throw new AssertionFailedError("Identified bug 46918"); + } + throw e; + } + + byte expReserData[] = HexRead.readFromString("1E 14 00 0A FF FF FF FF 00 00" + + "FF FF 00 00 00 00 00 00 00 00"); + + TestcaseRecordInputStream.confirmRecordEncoding(ExtendedPivotTableViewFieldsRecord.sid, expReserData, rec.serialize()); + } }