{"record":{"id":"b400842052f59a7b","repo":"Yalantis/uCrop","slug":"save-gzip-external-failed-to-save-file-s-wit","errorCode":null,"errorMessage":"save_gzip_external(): Failed to save file '%s' with external command 'gzip'.","messagePattern":"save_gzip_external\\(\\): Failed to save file '(.+?)' with external command 'gzip'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":63689,"sourceCode":"        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.cimg\",\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.cimg\",\n                             cimg::temporary_path(),cimg_file_separator,cimg::filenamerand());\n        }\n      } while (cimg::path_exists(filename_tmp));\n      save(filename_tmp);\n      cimg_snprintf(command,command._width,\"\\\"%s\\\" -c \\\"%s\\\" > \\\"%s\\\"\",\n                    cimg::gzip_path(),\n                    CImg<charT>::string(filename_tmp)._system_strescape().data(),\n                    CImg<charT>::string(filename)._system_strescape().data());\n      if (cimg::system(command,cimg::gzip_path())!=0)\n        throw CImgIOException(_cimg_instance\n                              \"save_gzip_external(): Failed to save file '%s' with external command 'gzip'.\",\n                              cimg_instance,\n                              filename);\n      if (!cimg::path_exists(filename))\n        throw CImgIOException(_cimg_instance\n                              \"save_gzip_external(): Failed to save file '%s' with external command 'gzip'.\",\n                              cimg_instance,\n                              filename);\n\n      std::remove(filename_tmp);\n      return *this;\n    }\n\n    //! Save image using GraphicsMagick's external binary.\n    /**\n       \\param filename Filename, as a C-string.\n       \\param quality Image quality (expressed in percent), when the file format supports it.\n       \\note This method uses \\c gm, an external executable binary provided by","sourceCodeStart":63671,"sourceCodeEnd":63707,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L63671-L63707","documentation":"save_gzip_external() runs the gzip executable via cimg::system(); a non-zero exit status means the external compression failed, so it throws CImgIOException for the given filename. Common causes are gzip not installed/not on PATH (cimg::gzip_path() empty or wrong), or the spawned command failing on the escaped file paths.","triggerScenarios":"gzip binary missing or not executable on the system; cimg::gzip_path() pointing to a wrong location; shell metacharacters in the temp or target path breaking the quoted command; disk full or permission denied during compression.","commonSituations":"Docker/CI images without the gzip package; Windows environments where gzip isn't available; sandboxed processes lacking shell access to run the external command.","solutions":["Install gzip (apt-get install gzip / apk add gzip) or ensure it's on PATH.","Verify cimg::gzip_path() resolves to a working binary; set the appropriate path if needed.","Check the target directory is writable and has space.","Replace with in-process compression (zlib) to avoid external dependency."],"exampleFix":"// before\nimg.save_gzip_external(\"out.cimg.gz\"); // fails if gzip absent\n// after\n#ifdef cimg_use_zlib\n/* use built-in zlib-based save */\n#else\nif (std::system(\"gzip --version > /dev/null 2>&1\") == 0)\n  img.save_gzip_external(\"out.cimg.gz\");\nelse\n  std::fprintf(stderr, \"gzip not installed\\n\");\n#endif","handlingStrategy":"try-catch","validationCode":"bool gzipAvailable = std::system(\"gzip --version > /dev/null 2>&1\") == 0;\nif (gzipAvailable) img.save_gzip_external(\"out.cimg.gz\");","typeGuard":null,"tryCatchPattern":"try { img.save_gzip_external(target); }\ncatch (cimg_library::CImgIOException &e) {\n  std::fprintf(stderr, \"gzip external save failed: %s\\n\", e.what());\n  img.save(\"out.cimg\"); // fallback: uncompressed\n}","preventionTips":["Install gzip in the deployment image (apt/apk/yum).","Escape or avoid shell-special characters in file paths.","Ensure ample disk space and write permissions in the target directory.","Fall back to uncompressed saving when external tools are unavailable."],"tags":["cimg","gzip","external-tool","command-failed","compression"],"backgroundTag":"command-not-found","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"}