mirror of https://github.com/apache/poi.git
Bug 61911: Avoid IndexOutOfBounds access when reading pictures
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1819403 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
62c8296c70
commit
89e7fbe6cd
|
@ -68,13 +68,10 @@ public class RecordsStresser {
|
||||||
// a test-case to test this locally without executing the full TestAllFiles
|
// a test-case to test this locally without executing the full TestAllFiles
|
||||||
@Test
|
@Test
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
InputStream stream = new FileInputStream("test-data/spreadsheet/15556.xls");
|
try (InputStream stream = new FileInputStream("test-data/spreadsheet/15556.xls")) {
|
||||||
try {
|
|
||||||
HSSFWorkbook wb = new HSSFWorkbook(stream);
|
HSSFWorkbook wb = new HSSFWorkbook(stream);
|
||||||
handleWorkbook(wb);
|
handleWorkbook(wb);
|
||||||
wb.close();
|
wb.close();
|
||||||
} finally {
|
|
||||||
stream.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,12 @@ import static org.junit.Assert.assertNotNull;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
import org.apache.poi.hwpf.extractor.WordExtractor;
|
import org.apache.poi.hwpf.extractor.WordExtractor;
|
||||||
|
import org.apache.poi.hwpf.model.PicturesTable;
|
||||||
|
import org.apache.poi.hwpf.usermodel.Picture;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class HWPFFileHandler extends POIFSFileHandler {
|
public class HWPFFileHandler extends POIFSFileHandler {
|
||||||
|
@ -33,7 +36,11 @@ public class HWPFFileHandler extends POIFSFileHandler {
|
||||||
assertNotNull(doc.getBookmarks());
|
assertNotNull(doc.getBookmarks());
|
||||||
assertNotNull(doc.getCharacterTable());
|
assertNotNull(doc.getCharacterTable());
|
||||||
assertNotNull(doc.getEndnotes());
|
assertNotNull(doc.getEndnotes());
|
||||||
|
|
||||||
|
PicturesTable picturesTable = doc.getPicturesTable();
|
||||||
|
List<Picture> pictures = picturesTable.getAllPictures();
|
||||||
|
assertNotNull(pictures);
|
||||||
|
|
||||||
handlePOIDocument(doc);
|
handlePOIDocument(doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,11 +61,8 @@ public class HWPFFileHandler extends POIFSFileHandler {
|
||||||
|
|
||||||
stream = new FileInputStream(file);
|
stream = new FileInputStream(file);
|
||||||
try {
|
try {
|
||||||
WordExtractor extractor = new WordExtractor(stream);
|
try (WordExtractor extractor = new WordExtractor(stream)) {
|
||||||
try {
|
|
||||||
assertNotNull(extractor.getText());
|
assertNotNull(extractor.getText());
|
||||||
} finally {
|
|
||||||
extractor.close();
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
stream.close();
|
stream.close();
|
||||||
|
|
|
@ -304,6 +304,10 @@ public final class StyleSheet {
|
||||||
return NIL_CHP;
|
return NIL_CHP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (styleIndex == -1) {
|
||||||
|
return NIL_CHP;
|
||||||
|
}
|
||||||
|
|
||||||
return (_styleDescriptions[styleIndex] != null ? _styleDescriptions[styleIndex]
|
return (_styleDescriptions[styleIndex] != null ? _styleDescriptions[styleIndex]
|
||||||
.getCHP() : NIL_CHP);
|
.getCHP() : NIL_CHP);
|
||||||
}
|
}
|
||||||
|
@ -318,6 +322,10 @@ public final class StyleSheet {
|
||||||
return NIL_PAP;
|
return NIL_PAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (styleIndex == -1) {
|
||||||
|
return NIL_PAP;
|
||||||
|
}
|
||||||
|
|
||||||
if (_styleDescriptions[styleIndex] == null) {
|
if (_styleDescriptions[styleIndex] == null) {
|
||||||
return NIL_PAP;
|
return NIL_PAP;
|
||||||
}
|
}
|
||||||
|
@ -338,6 +346,10 @@ public final class StyleSheet {
|
||||||
return NIL_CHPX;
|
return NIL_CHPX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (styleIndex == -1) {
|
||||||
|
return NIL_CHPX;
|
||||||
|
}
|
||||||
|
|
||||||
if (_styleDescriptions[styleIndex] == null) {
|
if (_styleDescriptions[styleIndex] == null) {
|
||||||
return NIL_CHPX;
|
return NIL_CHPX;
|
||||||
}
|
}
|
||||||
|
@ -358,6 +370,10 @@ public final class StyleSheet {
|
||||||
return NIL_PAPX;
|
return NIL_PAPX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (styleIndex == -1) {
|
||||||
|
return NIL_PAPX;
|
||||||
|
}
|
||||||
|
|
||||||
if (_styleDescriptions[styleIndex] == null) {
|
if (_styleDescriptions[styleIndex] == null) {
|
||||||
return NIL_PAPX;
|
return NIL_PAPX;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,7 @@ import org.apache.poi.hwpf.converter.AbstractWordUtils;
|
||||||
import org.apache.poi.hwpf.converter.WordToTextConverter;
|
import org.apache.poi.hwpf.converter.WordToTextConverter;
|
||||||
import org.apache.poi.hwpf.extractor.Word6Extractor;
|
import org.apache.poi.hwpf.extractor.Word6Extractor;
|
||||||
import org.apache.poi.hwpf.extractor.WordExtractor;
|
import org.apache.poi.hwpf.extractor.WordExtractor;
|
||||||
import org.apache.poi.hwpf.model.FieldsDocumentPart;
|
import org.apache.poi.hwpf.model.*;
|
||||||
import org.apache.poi.hwpf.model.FileInformationBlock;
|
|
||||||
import org.apache.poi.hwpf.model.PlexOfField;
|
|
||||||
import org.apache.poi.hwpf.model.SubdocumentType;
|
|
||||||
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.util.IOUtils;
|
import org.apache.poi.util.IOUtils;
|
||||||
|
@ -903,4 +900,17 @@ public class TestBugs{
|
||||||
HWPFDocument document = HWPFTestDataSamples.openSampleFile("ca.kwsymphony.www_education_School_Concert_Seat_Booking_Form_2011-12.doc");
|
HWPFDocument document = HWPFTestDataSamples.openSampleFile("ca.kwsymphony.www_education_School_Concert_Seat_Booking_Form_2011-12.doc");
|
||||||
document.close();
|
document.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test61911() throws IOException {
|
||||||
|
HWPFDocument document = HWPFTestDataSamples.openSampleFile("61911.doc");
|
||||||
|
|
||||||
|
PicturesTable picturesTable = document.getPicturesTable();
|
||||||
|
List<Picture> pictures = picturesTable.getAllPictures();
|
||||||
|
assertNotNull(pictures);
|
||||||
|
assertEquals(0, pictures.size());
|
||||||
|
|
||||||
|
document.close();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue