Author: kiwiwings
Date: Thu Apr 16 22:11:34 2020
New Revision: 1876641
URL: http://svn.apache.org/viewvc?rev=1876641&view=rev
Log:
#57843 - RuntimeException on extracting text from Word 97-2004 Document
Modified:
poi/site/src/documentation/content/xdocs/changes.xml
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java
poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
Modified: poi/site/src/documentation/content/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/poi/site/src/documentation/content/xdocs/changes.xml?rev=1876641&r1=1876640&r2=1876641&view=diff
==============================================================================
--- poi/site/src/documentation/content/xdocs/changes.xml (original)
+++ poi/site/src/documentation/content/xdocs/changes.xml Thu Apr 16 22:11:34
2020
@@ -91,6 +91,7 @@
<action type="fix" fixes-bug="64301" context="OPC">Allow
try-with-resources with OPCPackage.revert()</action>
<action type="fix" fixes-bug="63745" context="HSSF">Add traversing
and debugging interface to HSSF</action>
<action type="fix" fixes-bug="64350" context="POI_Overall">Sonar
fix - "Iterator.next()" methods should throw "NoSuchElementException"</action>
+ <action type="fix" fixes-bug="57843"
context="HWPF">RuntimeException on extracting text from Word 97-2004
Document</action>
</actions>
</release>
Modified:
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java?rev=1876641&r1=1876640&r2=1876641&view=diff
==============================================================================
---
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java
(original)
+++
poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/PAPFormattedDiskPage.java
Thu Apr 16 22:11:34 2020
@@ -137,18 +137,13 @@ public final class PAPFormattedDiskPage
{
int papxOffset = 2 * LittleEndian.getUByte(_fkp, _offset + (((_crun +
1) * FC_SIZE) + (index * BX_SIZE)));
int size = 2 * LittleEndian.getUByte(_fkp, _offset + papxOffset);
- if(size == 0)
- {
+ if(size == 0) {
size = 2 * LittleEndian.getUByte(_fkp, _offset + ++papxOffset);
- }
- else
- {
+ } else {
size--;
}
- byte[] papx = IOUtils.safelyAllocate(size, 512);
- System.arraycopy(_fkp, _offset + ++papxOffset, papx, 0, size);
- return papx;
+ return IOUtils.safelyClone(_fkp, _offset + papxOffset + 1, size, 512);
}
/**
@@ -273,8 +268,7 @@ public final class PAPFormattedDiskPage
// LittleEndian.putUShort( dataStream, hugeGrpprlOffset,
// grpprl.length - 2 );
- byte[] hugePapx = new byte[grpprl.length - 2];
- System.arraycopy( grpprl, 2, hugePapx, 0, grpprl.length - 2 );
+ byte[] hugePapx = Arrays.copyOfRange(grpprl, 2, grpprl.length);
int dataStreamOffset = dataStream.size();
dataStream.write( hugePapx );
Modified:
poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java?rev=1876641&r1=1876640&r2=1876641&view=diff
==============================================================================
---
poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
(original)
+++
poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestBugs.java
Thu Apr 16 22:11:34 2020
@@ -195,25 +195,25 @@ public class TestBugs{
*/
@Test
public void test44431_2() throws IOException {
- assertEqualsIgnoreNewline("File name=FieldsTest.doc\n" +
- "\n" +
- "\n" +
- "STYLEREF test\n" +
- "\n" +
- "\n" +
- "\n" +
- "TEST TABLE OF CONTENTS\n" +
- "\n" +
- "Heading paragraph in next page\t2\n" +
- "Another heading paragraph in further page\t3\n" +
- "Another heading paragraph in further page\t3\n" +
- "\n" +
- "\n" +
- "Heading paragraph in next page\n" +
- "Another heading paragraph in further page\n" +
- "\n" +
- "\n" +
- "\n" +
+ assertEqualsIgnoreNewline("File name=FieldsTest.doc\n" +
+ "\n" +
+ "\n" +
+ "STYLEREF test\n" +
+ "\n" +
+ "\n" +
+ "\n" +
+ "TEST TABLE OF CONTENTS\n" +
+ "\n" +
+ "Heading paragraph in next page\t2\n" +
+ "Another heading paragraph in further page\t3\n" +
+ "Another heading paragraph in further page\t3\n" +
+ "\n" +
+ "\n" +
+ "Heading paragraph in next page\n" +
+ "Another heading paragraph in further page\n" +
+ "\n" +
+ "\n" +
+ "\n" +
"Page 3 of 3", getText("Bug44431.doc"));
}
@@ -484,7 +484,7 @@ public class TestBugs{
HWPFDocument hwpfDocument =
HWPFTestDataSamples.openSampleFile(filename);
assertNotNull(filename,
hwpfDocument.getPicturesTable().getAllPictures());
-
+
hwpfDocument.close();
}
}
@@ -570,10 +570,8 @@ public class TestBugs{
public void test51604p3() throws Exception {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug51604.doc");
- byte[] originalData = new byte[doc.getFileInformationBlock()
- .getLcbDop()];
- System.arraycopy(doc.getTableStream(), doc.getFileInformationBlock()
- .getFcDop(), originalData, 0, originalData.length);
+ FileInformationBlock fib = doc.getFileInformationBlock();
+ byte[] originalData = Arrays.copyOfRange(doc.getTableStream(),
fib.getFcDop(), fib.getFcDop()+fib.getLcbDop());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
doc.getDocProperties().writeTo(outputStream);
@@ -731,11 +729,11 @@ public class TestBugs{
public void testBug53380_4() throws Exception {
assertNotNull(getText("Bug53380_4.doc"));
}
-
+
/**
- * java.lang.UnsupportedOperationException: Non-extended character
+ * java.lang.UnsupportedOperationException: Non-extended character
* Pascal strings are not supported right now
- *
+ *
* Disabled pending a fix for the bug
*/
@Test
@@ -744,7 +742,7 @@ public class TestBugs{
HWPFTestDataSamples.openSampleFile("56880.doc");
assertEqualsIgnoreNewline("Check Request", doc.getRange().text());
}
-
+
/**
* Bug 61268 - NegativeArraySizeException parsing word 97 document
*/
@@ -774,7 +772,7 @@ public class TestBugs{
}
else if(para.text().trim().equals("Section2")) {
assertSection2Margin(section);
-
+
// Change the margin widths
this.section2BottomMargin = (int)(1.5 *
AbstractWordUtils.TWIPS_PER_INCH);
this.section2TopMargin = (int)(1.75 *
AbstractWordUtils.TWIPS_PER_INCH);
@@ -787,7 +785,7 @@ public class TestBugs{
}
}
}
-
+
// Save away and re-read the document to prove the changes are
permanent
document = HWPFTestDataSamples.writeOutAndReadBack(document);
overallRange = document.getOverallRange();
@@ -849,8 +847,8 @@ public class TestBugs{
hwpfDocument2.close();
hwpfDocument.close();
}
-
- @Test(expected=ArrayIndexOutOfBoundsException.class)
+
+ @Test
public void test57843() throws IOException {
File f = POIDataSamples.getDocumentInstance().getFile("57843.doc");
try (POIFSFileSystem fs = new POIFSFileSystem(f, true)) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]