Yalantis/uCrop · error · CImgArgumentException

save_gzip_external(): Specified filename is (null).

Error message

save_gzip_external(): Specified filename is (null).

What it means

save_gzip_external() compresses the image by invoking the external gzip executable on a temporary file, redirecting output to the given filename. A null filename gives nothing to write to, so it throws CImgArgumentException immediately. gzip must be installed for the method to succeed.

Source

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

                                    cimg_instance);
      if (is_empty()) { cimg::fempty(0,filename); return *this; }

      CImgList<T> list;
      get_split('z').move_to(list);
      list.save_ffmpeg_external(filename,fps,codec,bitrate);
      return *this;
    }

    //! Save image using gzip external binary.
    /**
       \param filename Filename, as a C-string.
       \note This method uses \c gzip, an external executable binary provided by
         <a href="//http://www.gzip.org">gzip</a>.
       It must be installed for the method to succeed.
    **/
    const CImg<T>& save_gzip_external(const char *const filename) const {
      if (!filename)
        throw CImgArgumentException(_cimg_instance
                                    "save_gzip_external(): Specified filename is (null).",
                                    cimg_instance);
      if (is_empty()) { cimg::fempty(0,filename); return *this; }

      CImg<charT> command(1024), filename_tmp(256), body(256);
      const char
        *ext = cimg::split_filename(filename,body),
        *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",
                             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",

View on GitHub (pinned to f788b534b4)

Solutions

  1. Pass a concrete filename, e.g. img.save_gzip_external("out.cimg.gz").
  2. Default the path if null before calling.
  3. Consider cimg-library's built-in gzip support or zlib-based saving if external tools are undesirable.

Example fix

// before
img.save_gzip_external(path); // path may be NULL
// after
img.save_gzip_external(path ? path : "image.cimg.gz");
Defensive patterns

Strategy: validation

Validate before calling

if (!fname || !*fname) fname = "image.cimg.gz";
img.save_gzip_external(fname);

Type guard

bool validPath(const char *p) { return p != nullptr && p[0] != '\0'; }

Try / catch

try { img.save_gzip_external(path.c_str()); }
catch (cimg_library::CImgArgumentException &e) { std::fprintf(stderr, "gzip save: %s\n", e.what()); }

Prevention

When it happens

Trigger: Calling save_gzip_external(NULL) or with a filename variable that is null (defaulted char* never assigned).

Common situations: Downstream of a failed path resolution; portable code paths where filename construction was skipped; calling it on Windows without gzip installed (the null check fires first, missing-gzip surfaces later as a different error).

Related errors


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