{"record":{"id":"3ce06fe561d72e85","repo":"Yalantis/uCrop","slug":"load-jxl-failed-to-get-file-size-s","errorCode":null,"errorMessage":"load_jxl(): Failed to get file size '%s'.","messagePattern":"load_jxl\\(\\): Failed to get file size '(.+?)'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57143,"sourceCode":"    CImg<T>& _load_jxl(std::FILE *const file, const char *const filename) {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_jxl(): Specified filename is (null).\",\n                                    cimg_instance);\n\n#ifndef cimg_use_jxl\n      if (file)\n        throw CImgIOException(_cimg_instance\n                              \"load_jxl(): Unable to load data from '(FILE*)' unless libjxl is enabled.\",\n                              cimg_instance);\n      else return load_other(filename);\n#else\n      const char *nfilename = filename;\n      std::FILE *nfile = file?file:cimg::fopen(nfilename,\"rb\");\n      const long dataSize = cimg::fsize(nfile);\n      if (dataSize<=0) {\n        cimg::fclose(nfile);\n        throw CImgIOException(_cimg_instance\n                              \"load_jxl(): Failed to get file size '%s'.\",\n                              cimg_instance,\n                              nfilename);\n      }\n      CImg<ucharT> buffer(dataSize);\n      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'.\",","sourceCodeStart":57125,"sourceCodeEnd":57161,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57125-L57161","documentation":"CImg's load_jxl() first opens the file and calls cimg::fsize() to determine the JPEG XL data size; a non-positive result makes further reading impossible. The library deliberately aborts the load instead of attempting a blind decode. It indicates the file could not be sized (missing, unreadable, or special/empty file).","triggerScenarios":"CImg<T>::load_jxl(filename) is called and cimg::fsize() returns <= 0: the path does not exist, points to an empty file, or the FILE* cannot be stat'd/fseek'd to the end.","commonSituations":"Passing a wrong or typo'd path, a zero-byte .jxl file, a directory instead of a file, or a file stream that is already at EOF/unreadable due to permissions on Android NDK (ucrop JNI context).","solutions":["Verify the file exists, is non-empty, and is readable before calling load_jxl() (e.g. check with stat/access).","Correct the filename/path; on Android confirm the path is in app-accessible storage and the asset was actually extracted to disk.","If loading from memory, use load_jxl(buffer, size) style overloads or wrap the data in a real file instead of a pipe/unseekable stream."],"exampleFix":"// before\nimg.load_jxl(path); // throws if path missing/empty\n// after\nstd::FILE* f = std::fopen(path, \"rb\");\nif (!f || cimg::fsize(f) <= 0) { /* handle invalid file */ }\nelse { std::fclose(f); img.load_jxl(path); }","handlingStrategy":"validation","validationCode":"bool canLoadJxl(const char* path) {\n  if (!path) return false;\n  std::FILE* f = std::fopen(path, \"rb\");\n  if (!f) return false;\n  long sz = cimg::fsize(f);\n  std::fclose(f);\n  return sz > 0;\n}","typeGuard":null,"tryCatchPattern":"try { img.load_jxl(path); } catch (CImgIOException& e) { log << \"unreadable jxl: \" << e.what(); usePlaceholder(); }","preventionTips":["Check file existence and size with stat/access before any load call","Extract Android assets to a real file before decoding; never pass pipes","Verify download/transfer completeness with checksums"],"tags":["image-loading","file-io","jxl","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"}