Yalantis/uCrop · error · CImgIOException
load_jxl(): Failed to load image data '%s'.
Error message
load_jxl(): Failed to load image data '%s'.
What it means
After configuring the decoder, load_jxl() feeds the raw file bytes with JxlDecoderSetInput(buffer, size). A return value other than JXL_DEC_SUCCESS means libjxl rejected the input buffer setup, so CImg destroys the decoder and throws. Note the message text is reused later for basic-info failure; this specific throw corresponds to the SetInput step.
Source
Thrown at ucrop/src/main/jni/CImg.h:57167
cimg::fread(buffer._data,buffer._width,nfile);
cimg::fclose(nfile);
bool hasAlpha = false, isGray = false;
uint32_t nChannels = 0;
JxlBasicInfo jxlInfo;
JxlPixelFormat format = { 1,JXL_TYPE_UINT8,cimg::endianness()?JXL_BIG_ENDIAN:JXL_LITTLE_ENDIAN,0 };
CImg<ucharT> imgData;
JxlDecoder *decoder = JxlDecoderCreate(NULL);
if (JXL_DEC_SUCCESS!=JxlDecoderSubscribeEvents(decoder,JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE)) {
JxlDecoderDestroy(decoder);
throw CImgIOException(_cimg_instance
"load_jxl(): Failed to configure decoder '%s'.",
cimg_instance,
nfilename);
}
if (JXL_DEC_SUCCESS!=JxlDecoderSetInput(decoder,buffer._data,buffer._width)) {
JxlDecoderDestroy(decoder);
throw CImgIOException(_cimg_instance
"load_jxl(): Failed to load image data '%s'.",
cimg_instance,
nfilename);
}
JxlDecoderCloseInput(decoder);
while (true) {
JxlDecoderStatus status = JxlDecoderProcessInput(decoder);
if (status==JXL_DEC_SUCCESS || status==JXL_DEC_FULL_IMAGE) break;
else if (status==JXL_DEC_ERROR || status==JXL_DEC_NEED_MORE_INPUT) {
JxlDecoderDestroy(decoder);
throw CImgIOException(_cimg_instance
"load_jxl(): Failed to decode image '%s'.",
cimg_instance,
nfilename);
} else if (status==JXL_DEC_BASIC_INFO) {
if (JXL_DEC_SUCCESS!=JxlDecoderGetBasicInfo(decoder,&jxlInfo)) {
JxlDecoderDestroy(decoder);View on GitHub (pinned to f788b534b4)
Solutions
- Check that the file was fully read: verify fread() returned dataSize bytes before calling load_jxl.
- Re-check the file's integrity/size; re-copy the .jxl file if it was truncated during transfer.
- If constructing buffers manually, ensure data is non-null and size equals the actual byte count.
Example fix
// before
CImg<unsigned char> buf(dataSize);
cimg::fread(buf._data, buf._width, file); // return ignored
img.load_jxl(...); // may throw at SetInput
// after
const size_t got = cimg::fread(buf._data, buf._width, file);
if (got != dataSize) { /* handle short read */ } Defensive patterns
Strategy: validation
Validate before calling
bool readFileFully(const char* path, CImg<unsigned char>& buf) {
std::FILE* f = std::fopen(path, "rb");
if (!f) return false;
long sz = cimg::fsize(f);
if (sz <= 0) { std::fclose(f); return false; }
buf.assign(sz);
size_t got = cimg::fread(buf._data, buf._width, f);
std::fclose(f);
return got == (size_t)sz;
} Try / catch
try { img.load_jxl(path); } catch (CImgIOException& e) { retryWithReCopiedFile(path); } Prevention
- Always check fread's return count equals expected size
- Detect truncated files via expected-size or checksum comparison
- Re-download/re-copy files that fail integrity checks
When it happens
Trigger: JxlDecoderSetInput(decoder, buffer._data, buffer._width) returns != JXL_DEC_SUCCESS, i.e. the input pointer/size pair was rejected (null data with non-zero size or invalid state).
Common situations: The file was read into an empty buffer (fread failure, truncated file between fsize and read), or memory pressure made the CImg buffer allocation degenerate.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- load_jxl(): Failed to get file size '%s'.
- load_jxl(): Failed to configure decoder '%s'.
- load_jxl(): Failed to decode image '%s'.
- load_jxl(): Does not support animated JPEG XL '%s'.
- load_jxl(): Failed to decode image data '%s'.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/950d8cab9b7a990f.
Report an issue: GitHub.