{"record":{"id":"950d8cab9b7a990f","repo":"Yalantis/uCrop","slug":"load-jxl-failed-to-load-image-data-s","errorCode":null,"errorMessage":"load_jxl(): Failed to load image data '%s'.","messagePattern":"load_jxl\\(\\): Failed to load image data '(.+?)'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57167,"sourceCode":"      cimg::fread(buffer._data,buffer._width,nfile);\n      cimg::fclose(nfile);\n\n      bool hasAlpha = false, isGray = false;\n      uint32_t nChannels = 0;\n      JxlBasicInfo jxlInfo;\n      JxlPixelFormat format = { 1,JXL_TYPE_UINT8,cimg::endianness()?JXL_BIG_ENDIAN:JXL_LITTLE_ENDIAN,0 };\n      CImg<ucharT> imgData;\n      JxlDecoder *decoder = JxlDecoderCreate(NULL);\n      if (JXL_DEC_SUCCESS!=JxlDecoderSubscribeEvents(decoder,JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE)) {\n        JxlDecoderDestroy(decoder);\n        throw CImgIOException(_cimg_instance\n                              \"load_jxl(): Failed to configure decoder '%s'.\",\n                              cimg_instance,\n                              nfilename);\n      }\n      if (JXL_DEC_SUCCESS!=JxlDecoderSetInput(decoder,buffer._data,buffer._width)) {\n        JxlDecoderDestroy(decoder);\n        throw CImgIOException(_cimg_instance\n                              \"load_jxl(): Failed to load image data '%s'.\",\n                              cimg_instance,\n                              nfilename);\n      }\n      JxlDecoderCloseInput(decoder);\n\n      while (true) {\n        JxlDecoderStatus status = JxlDecoderProcessInput(decoder);\n        if (status==JXL_DEC_SUCCESS || status==JXL_DEC_FULL_IMAGE) break;\n        else if (status==JXL_DEC_ERROR || status==JXL_DEC_NEED_MORE_INPUT) {\n          JxlDecoderDestroy(decoder);\n          throw CImgIOException(_cimg_instance\n                                \"load_jxl(): Failed to decode image '%s'.\",\n                                cimg_instance,\n                                nfilename);\n        } else if (status==JXL_DEC_BASIC_INFO) {\n          if (JXL_DEC_SUCCESS!=JxlDecoderGetBasicInfo(decoder,&jxlInfo)) {\n            JxlDecoderDestroy(decoder);","sourceCodeStart":57149,"sourceCodeEnd":57185,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57149-L57185","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nCImg<unsigned char> buf(dataSize);\ncimg::fread(buf._data, buf._width, file); // return ignored\nimg.load_jxl(...); // may throw at SetInput\n// after\nconst size_t got = cimg::fread(buf._data, buf._width, file);\nif (got != dataSize) { /* handle short read */ }","handlingStrategy":"validation","validationCode":"bool readFileFully(const char* path, CImg<unsigned char>& buf) {\n  std::FILE* f = std::fopen(path, \"rb\");\n  if (!f) return false;\n  long sz = cimg::fsize(f);\n  if (sz <= 0) { std::fclose(f); return false; }\n  buf.assign(sz);\n  size_t got = cimg::fread(buf._data, buf._width, f);\n  std::fclose(f);\n  return got == (size_t)sz;\n}","typeGuard":null,"tryCatchPattern":"try { img.load_jxl(path); } catch (CImgIOException& e) { retryWithReCopiedFile(path); }","preventionTips":["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"],"tags":["jxl","decoder-input","truncated-file","cimg"],"backgroundTag":"file-read-failed","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}