{"record":{"id":"e4ab0afd7fdfccc5","repo":"Yalantis/uCrop","slug":"get-shared-rows-invalid-request-of-a-shared-mem","errorCode":null,"errorMessage":"get_shared_rows(): Invalid request of a shared-memory subset (0->%u,%u->%u,%u,%u).","messagePattern":"get_shared_rows\\(\\): Invalid request of a shared-memory subset \\(0->%u,%u->%u,%u,%u\\)\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":41601,"sourceCode":"                                    cimg_instance,\n                                    x0,x1,y0,z0,c0);\n      return CImg<T>(_data + beg,x1 - x0 + 1,1,1,1,true);\n    }\n\n    //! Return a shared-memory image referencing a range of rows of the image instance.\n    /**\n       \\param y0 Y-coordinate of the starting row.\n       \\param y1 Y-coordinate of the ending row.\n       \\param z0 Z-coordinate.\n       \\param c0 C-coordinate.\n    **/\n    CImg<T> get_shared_rows(const unsigned int y0, const unsigned int y1,\n                             const unsigned int z0=0, const unsigned int c0=0) {\n      const ulongT\n        beg = (ulongT)offset(0,y0,z0,c0),\n        end = (ulongT)offset(0,y1,z0,c0);\n      if (beg>end || beg>=size() || end>=size())\n        throw CImgArgumentException(_cimg_instance\n                                    \"get_shared_rows(): Invalid request of a shared-memory subset \"\n                                    \"(0->%u,%u->%u,%u,%u).\",\n                                    cimg_instance,\n                                    _width - 1,y0,y1,z0,c0);\n      return CImg<T>(_data + beg,_width,y1 - y0 + 1,1,1,true);\n    }\n\n    //! Return a shared-memory image referencing a range of rows of the image instance \\const.\n    const CImg<T> get_shared_rows(const unsigned int y0, const unsigned int y1,\n                                   const unsigned int z0=0, const unsigned int c0=0) const {\n      const ulongT\n        beg = (ulongT)offset(0,y0,z0,c0),\n        end = (ulongT)offset(0,y1,z0,c0);\n      if (beg>end || beg>=size() || end>=size())\n        throw CImgArgumentException(_cimg_instance\n                                    \"get_shared_rows(): Invalid request of a shared-memory subset \"\n                                    \"(0->%u,%u->%u,%u,%u).\",\n                                    cimg_instance,","sourceCodeStart":41583,"sourceCodeEnd":41619,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L41583-L41619","documentation":"CImg<T>::get_shared_rows() returns a shared-memory image referencing rows y0..y1. It throws CImgArgumentException when the linear offsets are inverted (beg > end) or extend past the image size (beg >= size() or end >= size()), i.e. the requested row range does not fit inside the instance.","triggerScenarios":"Calling img.get_shared_rows(y0,y1,z0,c0) with y0 > y1, or y1 >= img.height(), or z0/c0 out of range so the offset for row y1 exceeds size().","commonSituations":"Passing an exclusive end row (height instead of height-1); loop bounds computed with '<' semantics fed directly as inclusive bounds; channel/depth indices exceeding the image's spectrum or depth.","solutions":["Ensure y0 <= y1 and y1 < img.height(); remember rows are inclusive bounds.","Clamp: y0 = std::min(y0, img.height()-1); y1 = std::min(y1, img.height()-1);","Check z0 < img.depth() and c0 < img.spectrum(), since bad z0/c0 also inflate the offset beyond size().","Switch from get_shared_rows to a full copy (get_rows / crop) if you actually need non-contiguous or resized output."],"exampleFix":"// before\nCImg<float> rows = img.get_shared_rows(0, img.height());  // exclusive end\n// after\nCImg<float> rows = img.get_shared_rows(0, img.height() - 1, z, c);","handlingStrategy":"validation","validationCode":"bool ok = y0 <= y1 && y1 < img.height() && z0 < img.depth() && c0 < img.spectrum();","typeGuard":null,"tryCatchPattern":"try { auto rows = img.get_shared_rows(y0, y1, z, c); }\ncatch (CImgArgumentException& e) { /* clamp y1 to height-1 and retry */ }","preventionTips":["Convert half-open [y0, y1) ranges to inclusive y1-1","Clamp row bounds to height-1","Verify z0/c0 fit depth/spectrum before shared access"],"tags":["cimg","shared-memory","bounds-check"],"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"}