{"record":{"id":"94753a7202cb6961","repo":"Yalantis/uCrop","slug":"load-jxl-failed-to-set-decode-buffer-s","errorCode":null,"errorMessage":"load_jxl(): Failed to set decode buffer '%s'.","messagePattern":"load_jxl\\(\\): Failed to set decode buffer '(.+?)'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57215,"sourceCode":"          }\n          hasAlpha = jxlInfo.alpha_bits!=0;\n          nChannels = hasAlpha?jxlInfo.num_color_channels + 1:jxlInfo.num_color_channels;\n          isGray = jxlInfo.num_color_channels==1;\n        } else if (status==JXL_DEC_NEED_IMAGE_OUT_BUFFER) {\n          std::size_t imgDataSize = 0;\n          format.num_channels = nChannels;\n          format.data_type = jxlInfo.bits_per_sample==16?JXL_TYPE_UINT16:JXL_TYPE_UINT8;\n          if (JXL_DEC_SUCCESS!=JxlDecoderImageOutBufferSize(decoder,&format,&imgDataSize)) {\n            JxlDecoderDestroy(decoder);\n            throw CImgIOException(_cimg_instance\n                                  \"load_jxl(): Failed to decode image data '%s'.\",\n                                  cimg_instance,\n                                  nfilename);\n          }\n          imgData.assign(imgDataSize);\n          if (JXL_DEC_SUCCESS!=JxlDecoderSetImageOutBuffer(decoder,&format,(void*)imgData.data(),imgDataSize)) {\n            JxlDecoderDestroy(decoder);\n            throw CImgIOException(_cimg_instance\n                                  \"load_jxl(): Failed to set decode buffer '%s'.\",\n                                  cimg_instance,\n                                  nfilename);\n          }\n        }\n      }\n\n      assign(jxlInfo.xsize,jxlInfo.ysize,1,nChannels);\n      T\n        *ptr_r = data(0,0,0,0),\n        *ptr_g = isGray?0:data(0,0,0,1),\n        *ptr_b = isGray?0:data(0,0,0,2),\n        *ptr_a = !hasAlpha?0:data(0,0,0,isGray?1:3);\n      switch (jxlInfo.bits_per_sample) {\n      case 8: {\n        cimg_forY(*this,y) {\n          const uint8_t *ptrs = (uint8_t*)&imgData[y*_width*_spectrum*sizeof(uint8_t)];\n          cimg_forX(*this,x) {","sourceCodeStart":57197,"sourceCodeEnd":57233,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57197-L57233","documentation":"After allocating imgData, load_jxl() hands the buffer to libjxl with JxlDecoderSetImageOutBuffer. A non-success return means libjxl refused the output buffer, so the decoder is destroyed and this error is thrown. Typically a size/format mismatch between the allocated buffer and what the decoder requires.","triggerScenarios":"JxlDecoderSetImageOutBuffer(decoder, &format, imgData.data(), imgDataSize) returns != JXL_DEC_SUCCESS during load_jxl()'s NEED_IMAGE_OUT_BUFFER handling.","commonSituations":"imgDataSize from JxlDecoderImageOutBufferSize not matching the assigned buffer (allocation failure of imgData.assign), or format struct mutated between the two calls (ABI mismatch across libjxl versions).","solutions":["Rebuild JNI code against the deployed libjxl version so JxlPixelFormat and size semantics match.","Confirm imgData.assign(imgDataSize) succeeded (buffer.data() non-null, correct size).","Upgrade CImg; check known libjxl issues around SetImageOutBuffer for your version."],"exampleFix":"// before\nimgData.assign(imgDataSize); // OOM -> null/short buffer\nJxlDecoderSetImageOutBuffer(...); // fails\n// after\nimgData.assign(imgDataSize);\nif (imgData.size() != imgDataSize) { /* handle alloc failure */ }\nJxlDecoderSetImageOutBuffer(dec, &format, imgData.data(), imgDataSize);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { img.load_jxl(path); } catch (CImgIOException& e) { if (strstr(e.what(), \"decode buffer\")) reportAllocationOrAbiIssue(e); }","preventionTips":["Check allocation success (imgData size) before handing buffers to libjxl","Match JxlPixelFormat struct exactly to the linked libjxl version","Watch memory budgets on mobile; large jxl frames need big output buffers"],"tags":["jxl","buffer","decode-failed","cimg"],"backgroundTag":"internal-invariant-violation","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"}