pdf.js/test/fuzz/jpx_image.fuzz.js
Tim van der Meij c08b09d3b9
Fix JpxImage API issues (PR 17946 follow-up)
This commit changes the `JpxImage.decode` method signature to define the
`ignoreColorSpace` argument as optional with a default value. Note that
we already set this default value in the `getBytes` method of the
`src/core/decode_stream.js` file since this option only seems useful for
certain special cases and therefore shouldn't be mandatory to provide.

Moreover, the JPX fuzzer is changed to use the new `JpxImage` API.
2024-04-16 18:02:47 +02:00

29 lines
616 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 {
JpxImage.decode(new Uint8Array(data));
} catch (error) {
if (error.message && !ignoredError(error)) {
throw error;
}
}
}
export { fuzz };