{"record":{"id":"1de7c477401c7acb","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-value-ac","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Value accessor '[]': Out-of-bounds sub-vector request (length: %ld, start: %ld, sub-length: %ld, step: %ld).\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Value accessor '\\[\\]': Out-of-bounds sub-vector request \\(length: %ld, start: %ld, sub-length: %ld, step: %ld\\)\\.\"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":30118,"sourceCode":"        }\n        return (S2 - S*S/siz)/(siz - 1);\n      }\n\n      static double mp_vector_copy(_cimg_math_parser& mp) {\n        std::memcpy(&_mp_arg(1) + 1,&_mp_arg(2) + 1,sizeof(double)*mp.opcode[3]);\n        return cimg::type<double>::nan();\n      }\n\n      static double mp_vector_crop(_cimg_math_parser& mp) {\n        double *ptrd = &_mp_arg(1) + 1;\n        const double *ptrs = &_mp_arg(2) + 1;\n        const longT\n          length = (longT)mp.opcode[3],\n          start = (longT)_mp_arg(4),\n          sublength = (longT)mp.opcode[5],\n          step = (longT)_mp_arg(6);\n        if (start<0 || start + step*(sublength-1)>=length)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Value accessor '[]': \"\n                                      \"Out-of-bounds sub-vector request \"\n                                      \"(length: %ld, start: %ld, sub-length: %ld, step: %ld).\",\n                                      mp.imgin.pixel_type(),length,start,sublength,step);\n        ptrs+=start;\n        if (step==1) std::memcpy(ptrd,ptrs,sublength*sizeof(double));\n        else for (longT k = 0; k<sublength; ++k) { *(ptrd++) = *ptrs; ptrs+=step; }\n        return cimg::type<double>::nan();\n      }\n\n      static double mp_vector_crop_ext(_cimg_math_parser& mp) {\n        double *const ptrd = &_mp_arg(1) + 1;\n        const double *const ptrs = &_mp_arg(2) + 1;\n        const unsigned int\n          w = (unsigned int)mp.opcode[3],\n          h = (unsigned int)mp.opcode[4],\n          d = (unsigned int)mp.opcode[5],\n          s = (unsigned int)mp.opcode[6],\n          dx = (unsigned int)mp.opcode[11],","sourceCodeStart":30100,"sourceCodeEnd":30136,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L30100-L30136","documentation":"The math parser value accessor '[]' can extract a sub-vector from a vector value given a start index, sub-length and step. It validates start + step*(sublength-1) against the source vector length; if the requested range extends past the end (or starts before 0), a CImgArgumentException details the length, start, sub-length and step.","triggerScenarios":"An expression like V[start,sublength,step] where start is negative or start + step*(sublength-1) >= length, e.g. taking 8 elements with step 2 starting at index 10 of a 16-element vector (10 + 2*7 = 24 >= 16).","commonSituations":"Hard-coded slice parameters reused after the vector's size changed; using step/stride slicing with off-by-one in the last-element computation; dynamic start values from prior computations going out of range.","solutions":["Clamp or recompute the slice so that 0 <= start and start + step*(sublength-1) < length.","Reduce sublength or step to fit the available range before slicing.","Compute sublength dynamically from the vector length instead of hard-coding it.","Catch CImgArgumentException and log length/start/sublength/step to locate the bad parameter."],"exampleFix":"// before: V[10,8,2]  // end=24 >= 16\n// after:  V[10,3,2]   // end=14 < 16","handlingStrategy":"validation","validationCode":"if (start < 0 || start + step * (sublength - 1) >= length)\n  throw std::runtime_error(\"sub-vector slice out of bounds\");","typeGuard":null,"tryCatchPattern":"try { img.evaluate(sliceExpr); } catch (const CImgArgumentException& e) { log(\"[] accessor out of bounds: \" << e.what()); }","preventionTips":["Compute sublength from the vector length, never hard-code","Remember the last element is start + step*(sublength-1)","Clamp start to [0, length-1] before slicing"],"tags":["cimg","math-parser","index-out-of-bounds","slicing"],"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"}