{"record":{"id":"e1dbb46d4507f5fc","repo":"Yalantis/uCrop","slug":"load-jxl-failed-to-decode-image-s","errorCode":null,"errorMessage":"load_jxl(): Failed to decode image '%s'.","messagePattern":"load_jxl\\(\\): Failed to decode image '(.+?)'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57179,"sourceCode":"                              \"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);\n            throw CImgIOException(_cimg_instance\n                                  \"load_jxl(): Failed to load image data '%s'.\",\n                                  cimg_instance,\n                                  nfilename);\n          }\n          if (jxlInfo.have_animation!=0) {\n            JxlDecoderDestroy(decoder);\n            throw CImgIOException(_cimg_instance\n                                  \"load_jxl(): Does not support animated JPEG XL '%s'.\",\n                                  cimg_instance,\n                                  nfilename);\n          }","sourceCodeStart":57161,"sourceCodeEnd":57197,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57161-L57197","documentation":"During the JxlDecoderProcessInput loop, status JXL_DEC_ERROR or JXL_DEC_NEED_MORE_INPUT means the bitstream could not be decoded (or was incomplete), so CImg destroys the decoder and throws. This is the generic 'not valid / corrupt JPEG XL data' failure.","triggerScenarios":"JxlDecoderProcessInput returns JXL_DEC_ERROR or JXL_DEC_NEED_MORE_INPUT inside load_jxl()'s decode loop, typically because the file is not a valid JXL codestream/container or is truncated.","commonSituations":"Renaming a JPEG/PNG to .jxl and feeding it to load_jxl, partially downloaded files, or ISOBMFF container with data CImg's simple single-pass loop does not supply (NEED_MORE_INPUT).","solutions":["Validate the file is a genuine JPEG XL image (check FF 0A signature or JXL container box) before loading.","Re-obtain a complete, untruncated copy of the file (verify size/checksum).","If the image may not be JXL, sniff the format first (cimg::file_type) and dispatch to the appropriate load_* function.","For NEED_MORE_INPUT caused by non-standard containers, decode with libjxl's cjxl/djxl-compatible reference setup or convert the file."],"exampleFix":"// before\nimg.load_jxl(userFile); // corrupt/renamed file throws\n// after\nif (cimg::file_type(userFile) != \"jxl\") { /* route to load_jpeg etc. */ }\nelse img.load_jxl(userFile);","handlingStrategy":"validation","validationCode":"bool looksLikeJxl(const unsigned char* d, size_t n) {\n  if (n < 2) return false;\n  if (d[0] == 0xFF && d[1] == 0x0A) return true; // codestream\n  return n >= 12 && std::memcmp(d, \"\\x00\\x00\\x00\\x0CJXL \", 8) == 0; // container\n}","typeGuard":null,"tryCatchPattern":"try { img.load_jxl(path); } catch (CImgIOException& e) { log(\"not valid jxl, falling back to sniffed loader\"); img.load(path); }","preventionTips":["Sniff file signature before choosing a decoder; never trust extensions","Reject or repair truncated files early (NEED_MORE_INPUT means incomplete)","Keep a fallback load() path that dispatches by detected format"],"tags":["jxl","decode-failed","corrupt-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"}