{"record":{"id":"e798c2ab9210b501","repo":"Yalantis/uCrop","slug":"load-gzip-external-failed-to-load-file-s-wit","errorCode":null,"errorMessage":"load_gzip_external(): Failed to load file '%s' with external command 'gunzip'.","messagePattern":"load_gzip_external\\(\\): Failed to load file '(.+?)' with external command 'gunzip'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":59741,"sourceCode":"      do {\n        if (!cimg::strcasecmp(ext,\"gz\")) {\n          if (*ext2) cimg_snprintf(filename_tmp,filename_tmp._width,\"%s%c%s.%s\",\n                                   cimg::temporary_path(),cimg_file_separator,cimg::filenamerand(),ext2);\n          else cimg_snprintf(filename_tmp,filename_tmp._width,\"%s%c%s\",\n                             cimg::temporary_path(),cimg_file_separator,cimg::filenamerand());\n        } else {\n          if (*ext) cimg_snprintf(filename_tmp,filename_tmp._width,\"%s%c%s.%s\",\n                                  cimg::temporary_path(),cimg_file_separator,cimg::filenamerand(),ext);\n          else cimg_snprintf(filename_tmp,filename_tmp._width,\"%s%c%s\",\n                             cimg::temporary_path(),cimg_file_separator,cimg::filenamerand());\n        }\n      } while (cimg::path_exists(filename_tmp));\n      cimg_snprintf(command,command._width,\"\\\"%s\\\" -c \\\"%s\\\" > \\\"%s\\\"\",\n                    cimg::gunzip_path(),\n                    CImg<charT>::string(filename)._system_strescape().data(),\n                    CImg<charT>::string(filename_tmp)._system_strescape().data());\n      if (cimg::system(command)!=0)\n        throw CImgIOException(_cimg_instance\n                              \"load_gzip_external(): Failed to load file '%s' with external command 'gunzip'.\",\n                              cimg_instance,\n                              filename);\n      if (!cimg::path_exists(filename_tmp)) {\n        cimg::fclose(cimg::fopen(filename,\"r\"));\n        throw CImgIOException(_cimg_instance\n                              \"load_gzip_external(): Failed to load file '%s' with external command 'gunzip'.\",\n                              cimg_instance,\n                              filename);\n\n      }\n      load(filename_tmp);\n      std::remove(filename_tmp);\n      return *this;\n    }\n\n    //! Load gzipped image file, using external tool 'gunzip' \\newinstance.\n    static CImg<T> get_load_gzip_external(const char *const filename) {","sourceCodeStart":59723,"sourceCodeEnd":59759,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L59723-L59759","documentation":"load_gzip_external() runs `\"gunzip\" -c \"<file>\" > <tmpfile>` via cimg::system(); a non-zero exit status throws this CImgIOException. The gunzip tool was found and launched, but the decompression command failed.","triggerScenarios":"Corrupt or truncated .gz payload (gunzip exits non-zero), gunzip not actually on PATH in a way cimg::gunzip_path() resolves oddly, or shell redirection failing (unwritable temp directory).","commonSituations":"Partially uploaded .gz files; files compressed with unsupported variants; restricted Android/app environments where exec of external binaries is blocked or PATH is empty; full temp filesystem.","solutions":["Run the same gunzip command manually to see the real failure","Verify gzip integrity with `gzip -t file.gz` before loading","Ensure the temp output directory is writable and gunzip exists (cimg::gunzip_path())","Decompress in-process with zlib (gzread) into memory and load via CImg from a temp plain file, avoiding external tools"],"exampleFix":"// before\nimg.load_gzip_external(\"data.cimg.gz\"); // gunzip exit != 0\n// after\nif (cimg::system(\"gzip -t data.cimg.gz\") == 0) {\n  img.load_gzip_external(\"data.cimg.gz\");\n} else {\n  // decompress with zlib in-process and load the plain file\n  decompress_zlib_to(\"data.cimg.gz\", \"/tmp/data.cimg\");\n  img.load_cimg(\"/tmp/data.cimg\");\n}","handlingStrategy":"try-catch","validationCode":"// test archive integrity and tool availability first\nbool gz_ok = cimg::system(\"gzip -t data.cimg.gz\") == 0;\nbool tool_ok = cimg::gunzip_path()[0] != '\\0';","typeGuard":null,"tryCatchPattern":"try {\n  img.load_gzip_external(path);\n} catch (CImgIOException& e) {\n  // decompress in-process with zlib, then load plain file\n  gunzip_to_temp(path, \"/tmp/out.cimg\");\n  img.load_cimg(\"/tmp/out.cimg\");\n}","preventionTips":["Validate .gz integrity (gzip -t) before loading","Confirm gunzip exists on PATH in the target environment","Check temp directory writability and disk space","Prefer zlib in-process decompression on constrained platforms"],"tags":["cimg","gzip","gunzip","external-tool","shell-command"],"backgroundTag":"external-tool-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"}