import org.junit.jupiter.api.Test;
public class HPSFFileHandler extends POIFSFileHandler {
- private static final String NL = System.getProperty("line.separator");
-
private static final ThreadLocal<File> copyOutput = ThreadLocal.withInitial(HPSFFileHandler::getTempFile);
static final Set<String> EXCLUDES_HANDLE_ADD = StressTestUtils.unmodifiableHashSet(
try (InputStream stream = new FileInputStream(path)) {
handleFile(stream, path);
}
- }
- // a test-case to test this locally without executing the full TestAllFiles
- @Test
- void testExtractor() {
- File file = new File("test-data/hpsf/TestBug44375.xls");
+ File file = new File(path);
assertDoesNotThrow(() -> handleExtracting(file));
+
+ handleAdditional(file);
}
}
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
+import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.IOUtils;
*/
protected byte[] getDocumentEntryBytes(String name, int encryptionOffset, final int len) throws IOException {
DirectoryNode dir = getDirectory();
- DocumentEntry documentProps = (DocumentEntry)dir.getEntry(name);
+ final Entry entry = dir.getEntry(name);
+ if (!(entry instanceof DocumentEntry)) {
+ throw new IllegalArgumentException("Had unexpected type of entry for name: " + name + ": " + entry);
+ }
+ DocumentEntry documentProps = (DocumentEntry) entry;
int streamSize = documentProps.getSize();
boolean isEncrypted = (encryptionOffset > -1 && getEncryptionInfo() != null);
import java.io.StringWriter;
import java.util.Arrays;
import java.util.List;
+import java.util.Locale;
import java.util.stream.Stream;
import javax.xml.transform.OutputKeys;
"password_password_cryptoapi.doc",
// WORD 2.0 file
"word2.doc",
- // Corrupt file
- "Fuzzed.doc"
+ // Excel file
+ "TestRobert_Flaherty.doc",
+ // Corrupt files
+ "Fuzzed.doc",
+ "clusterfuzz-testcase-minimized-POIHWPFFuzzer-5418937293340672.doc",
+ "TestHPSFWritingFunctionality.doc"
);
public static Stream<Arguments> files() {
- File directory = POIDataSamples.getDocumentInstance().getFile("../document" );
- FilenameFilter ff = (dir, name) -> name.endsWith(".doc") && !failingFiles.contains(name);
+ return Stream.concat(
+ Arrays.stream(getFiles(POIDataSamples.getDocumentInstance().getFile(""))),
+ Arrays.stream(getFiles(POIDataSamples.getHPSFInstance().getFile("")))
+ ).map(Arguments::of);
+ }
+
+ private static File[] getFiles(File directory) {
+ FilenameFilter ff = (dir, name) -> name.toLowerCase(Locale.ROOT).endsWith(".doc") && !failingFiles.contains(name);
File[] docs = directory.listFiles(ff);
assertNotNull(docs);
- return Arrays.stream(docs).map(Arguments::of);
+ return docs;
}
@ParameterizedTest
import java.io.FilenameFilter;
import java.io.InputStream;
import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
import java.util.stream.Stream;
-import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.EncryptedDocumentException;
public class TestWordToTextConverter {
private static final Logger LOG = LogManager.getLogger(WordToTextConverter.class);
+ private static final List<String> failingFiles = Arrays.asList(
+ // Excel file
+ "TestRobert_Flaherty.doc",
+ // Corrupt files
+ "clusterfuzz-testcase-minimized-POIHWPFFuzzer-5418937293340672.doc",
+ "TestHPSFWritingFunctionality.doc"
+ );
+
/**
* [FAILING] Bug 47731 - Word Extractor considers text copied from some
* website as an embedded object
}
public static Stream<Arguments> files() {
- String dataDirName = System.getProperty(POIDataSamples.TEST_PROPERTY,
- new File("test-data").exists() ? "test-data" : "../test-data");
-
- File[] documents = new File(dataDirName, "document").listFiles(
- (FilenameFilter) new SuffixFileFilter(".doc"));
- assertNotNull(documents);
+ return Stream.concat(
+ Arrays.stream(getFiles(POIDataSamples.getDocumentInstance().getFile(""))),
+ Arrays.stream(getFiles(POIDataSamples.getHPSFInstance().getFile("")))
+ ).map(Arguments::of);
+ }
- return Arrays.stream(documents).map(Arguments::of);
+ private static File[] getFiles(File directory) {
+ FilenameFilter ff = (dir, name) -> name.toLowerCase(Locale.ROOT).endsWith(".doc") && !failingFiles.contains(name);
+ File[] docs = directory.listFiles(ff);
+ assertNotNull(docs);
+ return docs;
}
}