2023-12-05 00:19:25 +09:00
|
|
|
import {
|
|
|
|
Jbig2Image,
|
|
|
|
setVerbosityLevel,
|
|
|
|
VerbosityLevel,
|
|
|
|
} from "../../build/image_decoders/pdf.image_decoders.mjs";
|
|
|
|
|
|
|
|
// Avoid unnecessary console "spam", by ignoring `info`/`warn` calls.
|
|
|
|
setVerbosityLevel(VerbosityLevel.ERRORS);
|
2023-11-26 08:24:21 +09:00
|
|
|
|
|
|
|
const ignored = ["Cannot read properties", "JBIG2 error"];
|
|
|
|
|
|
|
|
function ignoredError(error) {
|
|
|
|
return ignored.some(message => error.message.includes(message));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Buffer} data
|
|
|
|
*/
|
|
|
|
function fuzz(data) {
|
|
|
|
try {
|
|
|
|
new Jbig2Image().parse(new Uint8Array(data));
|
|
|
|
} catch (error) {
|
|
|
|
if (error.message && !ignoredError(error)) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export { fuzz };
|