Yalantis/uCrop · error · CImgIOException

load_gzip_external(): Specified filename is (null) or does n

Error message

load_gzip_external(): Specified filename is (null) or does not exist.

What it means

load_gzip_external() validates that filename is non-null and exists as a file via cimg::is_file(); otherwise it throws CImgIOException before invoking the external `gunzip` tool. Note this check throws CImgIOException (unlike the graphicsmagick variant which uses CImgArgumentException).

Source

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

#else
      load_pnm(filename_tmp);
#endif
      std::remove(filename_tmp);
      return *this;
    }

    //! Load image using GraphicsMagick's external tool 'gm' \newinstance.
    static CImg<T> get_load_graphicsmagick_external(const char *const filename) {
      return CImg<T>().load_graphicsmagick_external(filename);
    }

    //! Load gzipped image file, using external tool 'gunzip'.
    /**
       \param filename Filename, as a C-string.
    **/
    CImg<T>& load_gzip_external(const char *const filename) {
      if (!filename || !cimg::is_file(filename))
        throw CImgIOException(_cimg_instance
                              "load_gzip_external(): Specified filename is (null) or does not exist.",
                              cimg_instance);
      CImg<charT> command(1024), filename_tmp(256), body(256);
      const char
        *const ext = cimg::split_filename(filename,body),
        *const ext2 = cimg::split_filename(body,0);

      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());

View on GitHub (pinned to f788b534b4)

Solutions

  1. Stat the path (or cimg::is_file) before calling and handle absence gracefully
  2. Resolve to an absolute path from a known base directory
  3. Fix upstream packaging/asset deployment so the gz file exists at runtime
  4. If data is in memory, decompress with zlib directly instead of the external-tool loader

Example fix

// before
img.load_gzip_external(gzPath); // may not exist
// after
if (cimg::is_file(gzPath)) {
  img.load_gzip_external(gzPath);
} else {
  cimg::dialog? // no; use:
  throw std::runtime_error("gzip file missing: " + std::string(gzPath));
}
Defensive patterns

Strategy: validation

Validate before calling

if (!gzPath || !cimg::is_file(gzPath)) {
  throw std::runtime_error("gzip file missing before load_gzip_external");
}
img.load_gzip_external(gzPath);

Type guard

bool existing_file(const char* f) { return f != nullptr && cimg::is_file(f); }

Try / catch

try {
  img.load_gzip_external(path);
} catch (CImgIOException& e) {
  if (!cimg::is_file(path)) rethrow; // precondition failure vs decode failure
  // else handle decompression issue
}

Prevention

When it happens

Trigger: Calling load_gzip_external(NULL), a non-existent path, a directory, or a dangling symlink.

Common situations: Assuming the .cimg/.gz file was decompressed elsewhere first; wrong relative path after a working-directory change; build pipeline not shipping the gz asset.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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