{"record":{"id":"d760667a5b62de14","repo":"Yalantis/uCrop","slug":"load-tiff-invalid-specified-frame-range-is-u","errorCode":null,"errorMessage":"load_tiff(): Invalid specified frame range is [%u,%u] (step %u) since file '%s' contains %u image(s).","messagePattern":"load_tiff\\(\\): Invalid specified frame range is \\[%u,%u\\] \\(step %u\\) since file '(.+?)' contains %u image\\(s\\)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":67656,"sourceCode":"      cimg::unused(bits_per_value,voxel_size,description);\n      if (nfirst_frame || nlast_frame!=~0U || nstep_frame!=1)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"load_tiff(): Unable to load sub-images from file '%s' unless libtiff is enabled.\",\n                                    cimglist_instance,\n                                    filename);\n\n      return assign(CImg<T>::get_load_tiff(filename));\n#else\n#if cimg_verbosity<3\n        TIFFSetWarningHandler(0);\n        TIFFSetErrorHandler(0);\n#endif\n      TIFF *tif = TIFFOpen(filename,\"r\");\n      if (tif) {\n        unsigned int nb_images = 0;\n        do ++nb_images; while (TIFFReadDirectory(tif));\n        if (nfirst_frame>=nb_images || (nlast_frame!=~0U && nlast_frame>=nb_images))\n          cimg::warn(_cimglist_instance\n                     \"load_tiff(): Invalid specified frame range is [%u,%u] (step %u) since \"\n                     \"file '%s' contains %u image(s).\",\n                     cimglist_instance,\n                     nfirst_frame,nlast_frame,nstep_frame,filename,nb_images);\n\n        if (nfirst_frame>=nb_images) return assign();\n        if (nlast_frame>=nb_images) nlast_frame = nb_images - 1;\n        assign(1 + (nlast_frame - nfirst_frame)/nstep_frame);\n        TIFFSetDirectory(tif,0);\n        cimglist_for(*this,l)\n          _data[l]._load_tiff(tif,nfirst_frame + l*nstep_frame,bits_per_value,voxel_size,description);\n        TIFFClose(tif);\n      } else throw CImgIOException(_cimglist_instance\n                                   \"load_tiff(): Failed to open file '%s'.\",\n                                   cimglist_instance,\n                                   filename);\n      return *this;\n#endif","sourceCodeStart":67638,"sourceCodeEnd":67674,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L67638-L67674","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Count TIFF pages first (e.g. via TIFFReadDirectory loop or identify from ImageMagick) and clamp the requested range","Handle the empty-list result: check is_empty()/size()==0 after load_tiff","Read metadata with a TIFF tool (tiffinfo) to confirm page count before batch-processing","If a shortened load is acceptable, rely on the returned list size instead of the requested range"],"exampleFix":"// before\nframes.load_tiff(\"scan.tiff\", 0, 9);\n// after\nframes.load_tiff(\"scan.tiff\", 0, 9);\nif (frames.is_empty()) {\n  // requested range not present in scan.tiff\n}","handlingStrategy":"validation","validationCode":"unsigned pages = countTiffPages(\"scan.tiff\"); // via TIFFReadDirectory loop\nif (first < pages) frames.load_tiff(\"scan.tiff\", first, std::min(last, pages-1));","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Count TIFF directories/pages before choosing a range","Check is_empty() after load_tiff","Clamp nlast_frame to page count - 1"],"tags":["cimg","tiff","frame-range"],"backgroundTag":"value-out-of-range","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}