pdf.js/test/fuzz/jpx_image.fuzz.js
Jonas Jenwald d7bec1b527 Limit the amount of console "spam" during fuzz tests (PR 17337 follow-up)
Having just tested PR 17337 locally I noticed that especially the `JpxImage`-test causes a "ridiculous" amount of warning messages to be printed, which doesn't seem helpful.
Given that only actual `Error`s should be relevant here, we can easily disable this logging during the tests.
2023-12-04 16:39:45 +01:00

30 lines
621 B
JavaScript

import {
JpxImage,
setVerbosityLevel,
VerbosityLevel,
} from "../../build/image_decoders/pdf.image_decoders.mjs";
// Avoid unnecessary console "spam", by ignoring `info`/`warn` calls.
setVerbosityLevel(VerbosityLevel.ERRORS);
const ignored = ["Cannot read properties", "JPX error"];
function ignoredError(error) {
return ignored.some(message => error.message.includes(message));
}
/**
* @param {Buffer} data
*/
function fuzz(data) {
try {
new JpxImage().parse(new Uint8Array(data));
} catch (error) {
if (error.message && !ignoredError(error)) {
throw error;
}
}
}
export { fuzz };