summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Vladimirov <sergey@apache.org>2012-09-11 19:49:44 +0000
committerSergey Vladimirov <sergey@apache.org>2012-09-11 19:49:44 +0000
commit861bccdf3c31ad9fae6e235ba96910823d3c28e8 (patch)
treecb9e2b92e5213bd01fa176970aaf026281f68e2d
parenta0ad9be37d61f5c11fe0bb49e824dfdd8127e4ed (diff)
downloadpoi-861bccdf3c31ad9fae6e235ba96910823d3c28e8.tar.gz
poi-861bccdf3c31ad9fae6e235ba96910823d3c28e8.zip
Fixed bug 53380 -- ArrayIndexOutOfBounds Excetion parsing word 97 document
We had incorrect implementation for sprmCShd80 (0x4866) 0x66 processing, Shd was used instead of Shd80 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1383584 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/documentation/content/xdocs/status.xml1
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/types/SHD80AbstractType.java53
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/model/types/SHDAbstractType.java69
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java19
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java16
-rw-r--r--src/types/definitions/shd80_type.xml14
-rw-r--r--src/types/definitions/shd_type.xml13
-rw-r--r--test-data/document/Bug53380_1.docbin0 -> 103424 bytes
-rw-r--r--test-data/document/Bug53380_2.docbin0 -> 31744 bytes
9 files changed, 141 insertions, 44 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index d1896df4e6..5ea601b4c1 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,6 +34,7 @@
<changes>
<release version="3.9-beta1" date="2012-??-??">
+ <action dev="poi-developers" type="fix">53380 - ArrayIndexOutOfBounds Excetion parsing word 97 document. </action>
<action dev="poi-developers" type="fix">53434 - Subtotal is not return correct value. </action>
<action dev="poi-developers" type="fix">53642 - [PATCH] XLS formula evaluation logging </action>
<action dev="poi-developers" type="fix">53561 - Unexpected adding of drawings into a workbook </action>
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/SHD80AbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/SHD80AbstractType.java
index 2a91c4b34f..1a617073d0 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/SHD80AbstractType.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/SHD80AbstractType.java
@@ -14,17 +14,18 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-package org.apache.poi.hwpf.model.types;
+package org.apache.poi.hwpf.model.types;
import org.apache.poi.util.BitField;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
/**
- * The SHD80 is a substructure of the CHP and PAP, and TC for Word 97. <p>Class
- and fields descriptions are quoted from
- Microsoft Office Word 97-2007 Binary File Format
+ * The Shd80 structure specifies the colors and pattern that are used for background
+ shading. As an exception to the constraints that are specified by Ico and Ipat, a Shd80 can
+ be set to Shd80Nil and specifies that no shading is applied. <p>Class and fields
+ descriptions are quoted from Word (.doc) Binary File Format by Microsoft Corporation
* <p>
* NOTE: This source is automatically generated please do not modify this file. Either subclass or
@@ -33,8 +34,7 @@ import org.apache.poi.util.LittleEndian;
* This class is internal. It content or properties may change without notice
* due to changes in our knowledge of internal Microsoft Word binary structures.
- * @author Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary File Format
- Specification [*.doc]
+ * @author Sergey Vladimirov; according to Word (.doc) Binary File Format by Microsoft Corporation.
*/
@Internal
@@ -42,9 +42,9 @@ public abstract class SHD80AbstractType
{
protected short field_1_value;
- /**/private static BitField icoFore = new BitField(0x001F);
- /**/private static BitField icoBack = new BitField(0x03E0);
- /**/private static BitField ipat = new BitField(0xFC00);
+ /**/private static final BitField icoFore = new BitField(0x001F);
+ /**/private static final BitField icoBack = new BitField(0x03E0);
+ /**/private static final BitField ipat = new BitField(0xFC00);
protected SHD80AbstractType()
{
@@ -52,12 +52,19 @@ public abstract class SHD80AbstractType
protected void fillFields( byte[] data, int offset )
{
- field_1_value = LittleEndian.getShort(data, 0x0 + offset);
+ field_1_value = LittleEndian.getShort( data, 0x0 + offset );
}
public void serialize( byte[] data, int offset )
{
- LittleEndian.putShort(data, 0x0 + offset, (short)field_1_value);
+ LittleEndian.putShort( data, 0x0 + offset, field_1_value );
+ }
+
+ public byte[] serialize()
+ {
+ final byte[] result = new byte[ getSize() ];
+ serialize( result, 0 );
+ return result;
}
/**
@@ -68,6 +75,30 @@ public abstract class SHD80AbstractType
return 0 + 2;
}
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ return true;
+ if ( obj == null )
+ return false;
+ if ( getClass() != obj.getClass() )
+ return false;
+ SHD80AbstractType other = (SHD80AbstractType) obj;
+ if ( field_1_value != other.field_1_value )
+ return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + field_1_value;
+ return result;
+ }
+
public String toString()
{
StringBuilder builder = new StringBuilder();
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/SHDAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/SHDAbstractType.java
index 16b99e1c33..13603ae7b2 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/SHDAbstractType.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/SHDAbstractType.java
@@ -14,6 +14,7 @@
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
+
package org.apache.poi.hwpf.model.types;
@@ -22,9 +23,9 @@ import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
/**
- * The SHD is a substructure of the CHP, PAP, and TC for Word 2000. <p>Class
+ * The Shd structure specifies the colors and pattern that are used for background shading. <p>Class
and
- fields descriptions are quoted from Microsoft Office Word 97-2007 Binary File Format
+ fields descriptions are quoted from Word (.doc) Binary File Format by Microsoft Corporation
* <p>
* NOTE: This source is automatically generated please do not modify this file. Either subclass or
@@ -33,8 +34,7 @@ import org.apache.poi.util.LittleEndian;
* This class is internal. It content or properties may change without notice
* due to changes in our knowledge of internal Microsoft Word binary structures.
- * @author Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary File Format
- Specification [*.doc]
+ * @author Sergey Vladimirov; according to Word (.doc) Binary File Format by Microsoft Corporation.
*/
@Internal
@@ -53,16 +53,23 @@ public abstract class SHDAbstractType
protected void fillFields( byte[] data, int offset )
{
- field_1_cvFore = new Colorref(data, 0x0 + offset);
- field_2_cvBack = new Colorref(data, 0x4 + offset);
- field_3_ipat = LittleEndian.getShort(data, 0x8 + offset);
+ field_1_cvFore = new Colorref( data, 0x0 + offset );
+ field_2_cvBack = new Colorref( data, 0x4 + offset );
+ field_3_ipat = LittleEndian.getShort( data, 0x8 + offset );
}
public void serialize( byte[] data, int offset )
{
- field_1_cvFore.serialize(data, 0x0 + offset);
- field_2_cvBack.serialize(data, 0x4 + offset);
- LittleEndian.putShort(data, 0x8 + offset, (short)field_3_ipat);
+ field_1_cvFore.serialize( data, 0x0 + offset );
+ field_2_cvBack.serialize( data, 0x4 + offset );
+ LittleEndian.putUShort( data, 0x8 + offset, field_3_ipat );
+ }
+
+ public byte[] serialize()
+ {
+ final byte[] result = new byte[ getSize() ];
+ serialize( result, 0 );
+ return result;
}
/**
@@ -73,6 +80,36 @@ public abstract class SHDAbstractType
return 0 + 4 + 4 + 2;
}
+ @Override
+ public boolean equals( Object obj )
+ {
+ if ( this == obj )
+ return true;
+ if ( obj == null )
+ return false;
+ if ( getClass() != obj.getClass() )
+ return false;
+ SHDAbstractType other = (SHDAbstractType) obj;
+ if ( field_1_cvFore != other.field_1_cvFore )
+ return false;
+ if ( field_2_cvBack != other.field_2_cvBack )
+ return false;
+ if ( field_3_ipat != other.field_3_ipat )
+ return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + field_1_cvFore.hashCode();
+ result = prime * result + field_2_cvBack.hashCode();
+ result = prime * result + field_3_ipat;
+ return result;
+ }
+
public String toString()
{
StringBuilder builder = new StringBuilder();
@@ -89,7 +126,7 @@ public abstract class SHDAbstractType
}
/**
- * 24-bit foreground color.
+ * A COLORREF that specifies the foreground color of ipat.
*/
@Internal
public Colorref getCvFore()
@@ -98,7 +135,7 @@ public abstract class SHDAbstractType
}
/**
- * 24-bit foreground color.
+ * A COLORREF that specifies the foreground color of ipat.
*/
@Internal
public void setCvFore( Colorref field_1_cvFore )
@@ -107,7 +144,7 @@ public abstract class SHDAbstractType
}
/**
- * 24-bit background color.
+ * A COLORREF that specifies the background color of ipat.
*/
@Internal
public Colorref getCvBack()
@@ -116,7 +153,7 @@ public abstract class SHDAbstractType
}
/**
- * 24-bit background color.
+ * A COLORREF that specifies the background color of ipat.
*/
@Internal
public void setCvBack( Colorref field_2_cvBack )
@@ -125,7 +162,7 @@ public abstract class SHDAbstractType
}
/**
- * Shading pattern.
+ * An Ipat that specifies the pattern used for shading.
*/
@Internal
public int getIpat()
@@ -134,7 +171,7 @@ public abstract class SHDAbstractType
}
/**
- * Shading pattern.
+ * An Ipat that specifies the pattern used for shading.
*/
@Internal
public void setIpat( int field_3_ipat )
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java
index 0af5b79848..bc3b798d45 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/CharacterSprmUncompressor.java
@@ -17,6 +17,8 @@
package org.apache.poi.hwpf.sprm;
+import org.apache.poi.hwpf.usermodel.ShadingDescriptor80;
+
import org.apache.poi.hwpf.model.Colorref;
import org.apache.poi.hwpf.model.Hyphenation;
import org.apache.poi.hwpf.usermodel.BorderCode;
@@ -578,9 +580,20 @@ public final class CharacterSprmUncompressor extends SprmUncompressor
case 0x65:
newCHP.setBrc (new BorderCode(sprm.getGrpprl(), sprm.getGrpprlOffset()));
break;
- case 0x66:
- newCHP.setShd (new ShadingDescriptor(sprm.getGrpprl(), sprm.getGrpprlOffset()));
- break;
+ case 0x66:
+ // sprmCShd80
+ /*
+ * "A Shd80 structure that specifies the background shading for the text. By default, text is not shaded."
+ *
+ * Word (.doc) Binary File Format. Copyright (c) 2011 Microsoft
+ * Corporation. Release: Tuesday, March 15, 2011
+ */
+ ShadingDescriptor80 oldDescriptor = new ShadingDescriptor80(
+ sprm.getGrpprl(), sprm.getGrpprlOffset() );
+ ShadingDescriptor newDescriptor = oldDescriptor
+ .toShadingDescriptor();
+ newCHP.setShd( newDescriptor );
+ break;
case 0x67:
// Obsolete
break;
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
index 6d69f68b9d..29638fd837 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
@@ -765,4 +765,20 @@ public class TestBugs extends TestCase
{
HWPFTestDataSamples.openSampleFile( "Bug52032_3.doc" );
}
+
+ /**
+ * Bug 53380 - ArrayIndexOutOfBounds Excetion parsing word 97 document
+ */
+ public void testBug53380_1() throws Exception
+ {
+ HWPFTestDataSamples.openSampleFile( "Bug53380_1.doc" );
+ }
+
+ /**
+ * Bug 53380 - ArrayIndexOutOfBounds Excetion parsing word 97 document
+ */
+ public void testBug53380_2() throws Exception
+ {
+ HWPFTestDataSamples.openSampleFile( "Bug53380_2.doc" );
+ }
}
diff --git a/src/types/definitions/shd80_type.xml b/src/types/definitions/shd80_type.xml
index ab3b45e4f4..22210ce7b0 100644
--- a/src/types/definitions/shd80_type.xml
+++ b/src/types/definitions/shd80_type.xml
@@ -19,17 +19,17 @@
-->
<record fromfile="true" name="SHD80" package="org.apache.poi.hwpf.model.types">
<suffix>AbstractType</suffix>
- <description>The SHD80 is a substructure of the CHP and PAP, and TC for Word 97. &lt;p&gt;Class
- and fields descriptions are quoted from
- Microsoft Office Word 97-2007 Binary File Format
+ <description>The Shd80 structure specifies the colors and pattern that are used for background
+ shading. As an exception to the constraints that are specified by Ico and Ipat, a Shd80 can
+ be set to Shd80Nil and specifies that no shading is applied. &lt;p&gt;Class and fields
+ descriptions are quoted from Word (.doc) Binary File Format by Microsoft Corporation
</description>
- <author>Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary File Format
- Specification [*.doc]
+ <author>Sergey Vladimirov; according to Word (.doc) Binary File Format by Microsoft Corporation.
</author>
<fields>
<field type="short" size="2" name="value">
- <bit number="1" mask="0x001F" name="icoFore" description="Foreground color" />
- <bit number="2" mask="0x03E0" name="icoBack" description="Background color" />
+ <bit number="1" mask="0x001F" name="icoFore" description="Foreground color"/>
+ <bit number="2" mask="0x03E0" name="icoBack" description="Background color"/>
<bit number="3" mask="0xFC00" name="ipat" description="Shading pattern"/>
</field>
</fields>
diff --git a/src/types/definitions/shd_type.xml b/src/types/definitions/shd_type.xml
index 940eaa99ab..a2c1ba6247 100644
--- a/src/types/definitions/shd_type.xml
+++ b/src/types/definitions/shd_type.xml
@@ -19,16 +19,15 @@
-->
<record fromfile="true" name="SHD" package="org.apache.poi.hwpf.model.types">
<suffix>AbstractType</suffix>
- <description>The SHD is a substructure of the CHP, PAP, and TC for Word 2000. &lt;p&gt;Class
+ <description>The Shd structure specifies the colors and pattern that are used for background shading. &lt;p&gt;Class
and
- fields descriptions are quoted from Microsoft Office Word 97-2007 Binary File Format
+ fields descriptions are quoted from Word (.doc) Binary File Format by Microsoft Corporation
</description>
- <author>Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary File Format
- Specification [*.doc]
+ <author>Sergey Vladimirov; according to Word (.doc) Binary File Format by Microsoft Corporation.
</author>
<fields>
- <field type="Colorref" size="4" name="cvFore" description="24-bit foreground color"/>
- <field type="Colorref" size="4" name="cvBack" description="24-bit background color"/>
- <field type="int" size="2" name="ipat" description="Shading pattern"/>
+ <field type="Colorref" size="4" name="cvFore" description="A COLORREF that specifies the foreground color of ipat"/>
+ <field type="Colorref" size="4" name="cvBack" description="A COLORREF that specifies the background color of ipat"/>
+ <field type="int" size="2" name="ipat" description="An Ipat that specifies the pattern used for shading"/>
</fields>
</record>
diff --git a/test-data/document/Bug53380_1.doc b/test-data/document/Bug53380_1.doc
new file mode 100644
index 0000000000..4233ac1e86
--- /dev/null
+++ b/test-data/document/Bug53380_1.doc
Binary files differ
diff --git a/test-data/document/Bug53380_2.doc b/test-data/document/Bug53380_2.doc
new file mode 100644
index 0000000000..1dd3daa184
--- /dev/null
+++ b/test-data/document/Bug53380_2.doc
Binary files differ