{"record":{"id":"c98c22e92a771bc8","repo":"Yalantis/uCrop","slug":"operator-invalid-image-request-at-position-u","errorCode":null,"errorMessage":"operator(): Invalid image request, at position [%u].","messagePattern":"operator\\(\\): Invalid image request, at position \\[%u\\]\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":64691,"sourceCode":"      static const CImgList<T> _empty;\n      return _empty;\n    }\n\n    //@}\n    //------------------------------------------\n    //\n    //! \\name Overloaded Operators\n    //@{\n    //------------------------------------------\n\n    //! Return a reference to one image element of the list.\n    /**\n       \\param pos Index of the image element.\n    **/\n    CImg<T>& operator()(const unsigned int pos) {\n#if cimg_verbosity>=3\n      if (pos>=_width) {\n        cimg::warn(_cimglist_instance\n                   \"operator(): Invalid image request, at position [%u].\",\n                   cimglist_instance,\n                   pos);\n        return *_data;\n      }\n#endif\n      return _data[pos];\n    }\n\n    //! Return a reference to one image of the list.\n    /**\n       \\param pos Index of the image element.\n    **/\n    const CImg<T>& operator()(const unsigned int pos) const {\n      return const_cast<CImgList<T>*>(this)->operator()(pos);\n    }\n\n    //! Return a reference to one pixel value of one image of the list.","sourceCodeStart":64673,"sourceCodeEnd":64709,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L64673-L64709","documentation":"CImgList<T>::operator()(pos) returns the image at index pos in the list. When cimg_verbosity>=3 and pos is out of range (pos>=_width, the list size), it emits a warning and returns a reference to the first image (*_data) instead of crashing. This is a silent-wrong-result hazard: the caller gets image 0 rather than the requested one.","triggerScenarios":"Calling list(pos) with an index >= list.size(); iterating a list that was reassigned/emptied (assign()) while old indices are still used; passing a frame index from a failed load (e.g. load_yuv/load_tiff returned fewer frames than requested) into operator().","commonSituations":"Looping over frames after a partial video/YUV load, reusing stale indices after assign(), off-by-one loops (i<=list.size()), or sharing a CImgList between threads while one thread resizes it.","solutions":["Check the index against list.size() before calling list(pos)","Use cimglist_for or cimglist_forin to iterate instead of manual indices","Verify the load actually produced the expected number of frames before accessing them (list.size() check)","Enable bounds-checked debugging during development (cimg_verbosity>=3 makes this warn instead of silently returning _data)"],"exampleFix":"// before\nCImg<unsigned char>& frame = frames(i);\n// after\nif (i < frames.size()) {\n  CImg<unsigned char>& frame = frames(i);\n} else {\n  // handle missing frame\n}","handlingStrategy":"validation","validationCode":"if (i >= 0 && (unsigned)i < frames.size()) { auto& img = frames(i); } else { /* handle */ }","typeGuard":"bool inRange(const CImgList<T>& l, unsigned i) { return i < l.size(); }","tryCatchPattern":null,"preventionTips":["Check list.size() before indexed access","Prefer cimglist_for iteration over manual indices","Re-check size after any load/assign"],"tags":["cimg","index-out-of-bounds","image-list"],"backgroundTag":"index-out-of-bounds","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"}