Skip to content

Commit

Permalink
Bug 66425: Avoid a NullPointerException found via oss-fuzz
Browse files Browse the repository at this point in the history
We try to avoid throwing NullPointerException, but it was possible
to trigger one here with a specially crafted input-file

Should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=62216

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1912250 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
centic9 committed Sep 11, 2023
1 parent 482f4ca commit dbd8808
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ Licensed to the Apache Software Foundation (ASF) under one or more

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -61,6 +63,7 @@ public abstract class BaseTestPPTIterating {
static {
EXCLUDED.put("clusterfuzz-testcase-minimized-POIHSLFFuzzer-6416153805979648.ppt", Exception.class);
EXCLUDED.put("clusterfuzz-testcase-minimized-POIHSLFFuzzer-6710128412590080.ppt", RuntimeException.class);
EXCLUDED.put("clusterfuzz-testcase-minimized-POIFuzzer-5429732352851968.ppt", FileNotFoundException.class);
}

public static Stream<Arguments> files() {
Expand Down Expand Up @@ -95,7 +98,11 @@ void tearDownBase() {
}

private static void findFile(List<Arguments> list, String dir) {
String[] files = new File(dir).list((arg0, arg1) -> arg1.toLowerCase(Locale.ROOT).endsWith(".ppt"));
File dirFile = new File(dir);
assertTrue(dirFile.exists(), "Directory does not exist: " + dirFile.getAbsolutePath());
assertTrue(dirFile.isDirectory(), "Not a directory: " + dirFile.getAbsolutePath());

String[] files = dirFile.list((arg0, arg1) -> arg1.toLowerCase(Locale.ROOT).endsWith(".ppt"));

assertNotNull(files, "Did not find any ppt files in directory " + dir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -56,6 +57,11 @@ void runOneFile(File pFile) throws Exception {
throw e;
}
}

// work around one file which works here but not in other tests
if (pFile.getName().equals("clusterfuzz-testcase-minimized-POIFuzzer-5429732352851968.ppt")) {
throw new FileNotFoundException();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ protected static Cipher initCipherForBlock(Cipher cipher, int block,
}

protected static SecretKey generateSecretKey(String password, EncryptionVerifier ver) {
if (password == null) {
throw new IllegalArgumentException("Did not receive a password");
}
if (password.length() > 255) {
password = password.substring(0, 255);
}
Expand Down
Binary file not shown.
Binary file modified test-data/spreadsheet/stress.xls
Binary file not shown.

0 comments on commit dbd8808

Please sign in to comment.