#57843 - RuntimeException on extracting text from Word 97-2004 Document

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876641 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2020-04-16 22:11:34 +00:00
parent 7daeb4278c
commit 7b2674f5af
2 changed files with 34 additions and 42 deletions

View File

@ -137,18 +137,13 @@ public final class PAPFormattedDiskPage extends FormattedDiskPage {
{
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 extends FormattedDiskPage {
// 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 );

View File

@ -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);
@ -850,7 +848,7 @@ public class TestBugs{
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)) {