Yalantis/uCrop · warning

load_tiff(): Invalid specified frame range is [%u,%u] (step…

Error message

load_tiff(): Invalid specified frame range is [%u,%u] (step %u) since file '%s' contains %u image(s).

What it means

CImgList<T>::load_tiff() warns that the requested frame range [nfirst_frame,nlast_frame] exceeds the number of image directories actually present in the TIFF file. When nfirst_frame >= nb_images the list is reset to empty (assign()); otherwise a shortened range is loaded.

Solutions

  1. Count TIFF pages first (e.g. via TIFFReadDirectory loop or identify from ImageMagick) and clamp the requested range
  2. Handle the empty-list result: check is_empty()/size()==0 after load_tiff
  3. Read metadata with a TIFF tool (tiffinfo) to confirm page count before batch-processing
  4. If a shortened load is acceptable, rely on the returned list size instead of the requested range

Example fix

// before
frames.load_tiff("scan.tiff", 0, 9);
// after
frames.load_tiff("scan.tiff", 0, 9);
if (frames.is_empty()) {
  // requested range not present in scan.tiff
}
Defensive patterns

Strategy: validation

Validate before calling

unsigned pages = countTiffPages("scan.tiff"); // via TIFFReadDirectory loop
if (first < pages) frames.load_tiff("scan.tiff", first, std::min(last, pages-1));

Prevention

When it happens

Trigger: Calling load_tiff(filename, nfirst_frame, nlast_frame, step) where nfirst_frame or nlast_frame >= the TIFF directory count; loading a single-page TIFF while requesting later frames; multi-page TIFF where pages were stripped/re-saved.

Common situations: Assuming a multi-page TIFF that is actually single-page; re-saved/compressed TIFFs that lost sub-pages; loop over fixed page counts against variable document scans.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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

Appendix: source

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

      cimg::unused(bits_per_value,voxel_size,description);
      if (nfirst_frame || nlast_frame!=~0U || nstep_frame!=1)
        throw CImgArgumentException(_cimglist_instance
                                    "load_tiff(): Unable to load sub-images from file '%s' unless libtiff is enabled.",
                                    cimglist_instance,
                                    filename);

      return assign(CImg<T>::get_load_tiff(filename));
#else
#if cimg_verbosity<3
        TIFFSetWarningHandler(0);
        TIFFSetErrorHandler(0);
#endif
      TIFF *tif = TIFFOpen(filename,"r");
      if (tif) {
        unsigned int nb_images = 0;
        do ++nb_images; while (TIFFReadDirectory(tif));
        if (nfirst_frame>=nb_images || (nlast_frame!=~0U && nlast_frame>=nb_images))
          cimg::warn(_cimglist_instance
                     "load_tiff(): Invalid specified frame range is [%u,%u] (step %u) since "
                     "file '%s' contains %u image(s).",
                     cimglist_instance,
                     nfirst_frame,nlast_frame,nstep_frame,filename,nb_images);

        if (nfirst_frame>=nb_images) return assign();
        if (nlast_frame>=nb_images) nlast_frame = nb_images - 1;
        assign(1 + (nlast_frame - nfirst_frame)/nstep_frame);
        TIFFSetDirectory(tif,0);
        cimglist_for(*this,l)
          _data[l]._load_tiff(tif,nfirst_frame + l*nstep_frame,bits_per_value,voxel_size,description);
        TIFFClose(tif);
      } else throw CImgIOException(_cimglist_instance
                                   "load_tiff(): Failed to open file '%s'.",
                                   cimglist_instance,
                                   filename);
      return *this;
#endif

View on GitHub (pinned to f788b534b4)