{"record":{"id":"6dd62cb3fd8b527f","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-6dd62c","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'copy()': Out-of-bounds image pointer (length: %ld, increment: %ld, offset start: %ld, offset end: %ld, offset max: %lu).\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'copy\\(\\)': Out-of-bounds image pointer \\(length: %ld, increment: %ld, offset start: %ld, offset end: %ld, offset max: %lu\\)\\.\"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":28878,"sourceCode":"        longT off = 0;\n        if (is_relative) {\n          ox = (int)mp.mem[_cimg_mp_slot_x];\n          oy = (int)mp.mem[_cimg_mp_slot_y];\n          oz = (int)mp.mem[_cimg_mp_slot_z];\n          oc = (int)mp.mem[_cimg_mp_slot_c];\n          off = img.offset(ox,oy,oz,oc);\n        }\n        if ((*p_ref)%2) {\n          const int\n            x = (int)mp.mem[p_ref[3]],\n            y = (int)mp.mem[p_ref[4]],\n            z = (int)mp.mem[p_ref[5]],\n            c = *p_ref==5?0:(int)mp.mem[p_ref[6]];\n          off+=img.offset(x,y,z,c);\n        } else off+=(longT)mp.mem[p_ref[3]];\n        const longT eoff = off + (siz - 1)*inc;\n        if (off<0 || eoff>=(longT)img.size())\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'copy()': \"\n                                      \"Out-of-bounds image pointer \"\n                                      \"(length: %ld, increment: %ld, offset start: %ld, \"\n                                      \"offset end: %ld, offset max: %lu).\",\n                                      mp.imgin.pixel_type(),siz,inc,off,eoff,img.size() - 1);\n        return (float*)&img[off];\n      }\n\n      static double mp_memcopy(_cimg_math_parser& mp) {\n        longT siz = (longT)_mp_arg(4);\n        const longT inc_d = (longT)_mp_arg(5), inc_s = (longT)_mp_arg(6);\n        const float\n          _opacity = (float)_mp_arg(7),\n          opacity = (float)cimg::abs(_opacity),\n          omopacity = 1 - std::max(_opacity,0.f);\n        if (siz>0) {\n          const bool\n            is_doubled = mp.opcode[8]<=1,\n            is_doubles = mp.opcode[15]<=1;","sourceCodeStart":28860,"sourceCodeEnd":28896,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L28860-L28896","documentation":"The math parser 'copy()' variant that writes into an image validates that the computed start offset and end offset (start + (siz-1)*inc) are inside the target image (0 <= off < img.size()). If the destination range falls outside the image buffer, a CImgArgumentException with the pointer details is thrown to prevent buffer overrun.","triggerScenarios":"copy(#ind,...) writing N values with stride inc into an image, where the computed end offset is >= img.size(), e.g. copy(#0, x + w*h, siz, inc, ...) near the image end, or x,y,z,c coordinates whose linear offset exceeds the image extent.","commonSituations":"Blitting a patch with a size larger than the destination image; coordinate arithmetic mistakes (width vs width-1); operating on an image after it was cropped/resized smaller.","solutions":["Verify img.size() (w*h*d*s) is large enough for the destination range before running the expression.","Reduce the copy length or increment so off + (siz-1)*inc < img.size().","Fix the x,y,z,c source coordinates so img.offset(x,y,z,c) lands inside the image.","Catch CImgArgumentException and report the computed off/eoff to the user."],"exampleFix":"// before: copy(#0, w*h, 4, 4, patch)  // past image end\n// after:  copy(#0, 0, 4, 4, patch)","handlingStrategy":"validation","validationCode":"const longT n = (longT)img.size();\nif (off < 0 || off + (siz - 1) * inc >= n)\n  throw std::runtime_error(\"copy() would overflow the target image\");","typeGuard":null,"tryCatchPattern":"try { img.evaluate(expr); } catch (const CImgArgumentException& e) { log(\"image copy out of bounds: \" << e.what()); }","preventionTips":["Validate destination patch fits the image (w*h*d*s)","Recompute offsets after any crop/resize of the image","Use img.offset(x,y,z,c) rather than hand-rolled index math"],"tags":["cimg","math-parser","index-out-of-bounds"],"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-14T05:17:10.506Z"}