Yalantis/uCrop · error · CImgIOException

load_gzip_external(): Failed to open file

Error message

load_gzip_external(): Failed to open file '%s'.

What it means

load_gzip_external() builds a command line like "gunzip" -c "file.gz" > tmpfile and runs it via cimg::system(). If that external command returns a nonzero exit status, CImg throws this CImgIOException. It means the gunzip process itself failed (tool missing, corrupt archive, permissions), even though the input file existed.

Solutions

  1. Install or verify the gunzip tool and ensure cimg::gunzip_path() points to it (check environment variable/compile-time path).
  2. Test decompression manually (gunzip -t file.gz) to rule out a corrupt archive.
  3. Ensure the temp directory (CImg tmpdir) is writable by the process.

Example fix

// before
list.load_gzip_external("data.bin.gz"); // fails silently when gunzip absent
// after
if (std::system("command -v gunzip >/dev/null")!=0)
  throw std::runtime_error("gunzip not installed");
list.load_gzip_external("data.bin.gz");
Defensive patterns

Strategy: fallback

Validate before calling

if (std::system("command -v gunzip >/dev/null 2>&1") != 0) {
  fprintf(stderr, "gunzip not available\n");
  return false;
}

Try / catch

try { list.load_gzip_external(path); }
catch (CImgIOException &e) { /* fall back to CImg's built-in gz loader or error out */ }

Prevention

When it happens

Trigger: cimg::system() returns !=0 after running cimg::gunzip_path() on the file; gunzip binary not installed; corrupted .gz; no write permission for the temp file directory.

Common situations: Deployed containers/images without the gzip package; gunzip path misconfigured; truncated or corrupt archive produced by a failed download; sandboxed app without temp dir write access.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/a4116ffd7eb633cd. Report an issue: GitHub.

Appendix: source

Thrown at ucrop/src/main/jni/CImg.h:67597

      do {
        if (!cimg::strcasecmp(ext,"gz")) {
          if (*ext2) cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s.%s",
                                   cimg::temporary_path(),cimg_file_separator,cimg::filenamerand(),ext2);
          else cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s",
                             cimg::temporary_path(),cimg_file_separator,cimg::filenamerand());
        } else {
          if (*ext) cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s.%s",
                                  cimg::temporary_path(),cimg_file_separator,cimg::filenamerand(),ext);
          else cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s",
                             cimg::temporary_path(),cimg_file_separator,cimg::filenamerand());
        }
      } while (cimg::path_exists(filename_tmp));
      cimg_snprintf(command,command._width,"\"%s\" -c \"%s\" > \"%s\"",
                    cimg::gunzip_path(),
                    CImg<charT>::string(filename)._system_strescape().data(),
                    CImg<charT>::string(filename_tmp)._system_strescape().data());
      if (cimg::system(command,cimg::gunzip_path())!=0)
        throw CImgIOException(_cimglist_instance
                              "load_gzip_external(): Failed to open file '%s'.",
                              cimglist_instance,
                              filename);
      if (!cimg::path_exists(filename_tmp)) {
        cimg::fclose(cimg::fopen(filename,"r"));
        throw CImgIOException(_cimglist_instance
                              "load_gzip_external(): Failed to open file '%s'.",
                              cimglist_instance,
                              filename);

      }
      load(filename_tmp);
      std::remove(filename_tmp);
      return *this;
    }

    //! Load a gzipped list, using external tool 'gunzip' \newinstance.
    static CImgList<T> get_load_gzip_external(const char *const filename) {

View on GitHub (pinned to f788b534b4)