{"record":{"id":"9b63e37eee630f2d","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-function-9b63e3","errorCode":null,"errorMessage":"\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': Target vector (%lu values) and its specified target geometry (%d,%d,%d,%d) (%lu values) do not match.\"","messagePattern":"\"\\[\" cimg_appname \"_math_parser\\] CImg<(.+?)>: Function 'draw\\(\\)': Target vector \\(%lu values\\) and its specified target geometry \\((.+?),(.+?),(.+?),(.+?)\\) \\(%lu values\\) do not match\\.\"","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":30167,"sourceCode":"        const double *const ptrs = &_mp_arg(7) + 1;\n        const unsigned int\n          sizD = (unsigned int)mp.opcode[2],\n          sizS = (unsigned int)mp.opcode[8];\n        const int\n          w = (int)_mp_arg(3), h = (int)_mp_arg(4), d = (int)_mp_arg(5), s = (int)_mp_arg(6),\n          x = (int)_mp_arg(9), y = (int)_mp_arg(10), z = (int)_mp_arg(11), c = (int)_mp_arg(12);\n        int dx = (int)mp.opcode[13], dy = (int)mp.opcode[14], dz = (int)mp.opcode[15], dc = (int)mp.opcode[16];\n        dx = (unsigned int)dx==~0U?w:(int)_mp_arg(13);\n        dy = (unsigned int)dy==~0U?h:(int)_mp_arg(14);\n        dz = (unsigned int)dz==~0U?d:(int)_mp_arg(15);\n        dc = (unsigned int)dc==~0U?s:(int)_mp_arg(16);\n\n        if (w<=0 || h<=0 || d<=0 || s<=0)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': \"\n                                      \"Invalid specified target vector geometry (%d,%d,%d,%d).\",\n                                      mp.imgin.pixel_type(),w,h,d,s);\n        if (sizD<(ulongT)w*h*d*s)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': \"\n                                      \"Target vector (%lu values) and its specified target geometry (%d,%d,%d,%d) \"\n                                      \"(%lu values) do not match.\",\n                                      mp.imgin.pixel_type(),sizD,w,h,d,s,(ulongT)w*h*d*s);\n        if (dx<=0 || dy<=0 || dz<=0 || dc<=0)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': \"\n                                      \"Invalid specified sprite geometry (%d,%d,%d,%d).\",\n                                      mp.imgin.pixel_type(),dx,dy,dz,dc);\n        if (sizS<(ulongT)dx*dy*dz*dc)\n          throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] CImg<%s>: Function 'draw()': \"\n                                      \"Sprite vector (%lu values) and its specified sprite geometry (%d,%d,%d,%d) \"\n                                      \"(%lu values) do not match.\",\n                                      mp.imgin.pixel_type(),sizS,dx,dy,dz,dc,(ulongT)dx*dy*dz*dc);\n\n        CImg<doubleT> D(ptrd,w,h,d,s,true);\n        const CImg<doubleT> S(ptrs,dx,dy,dz,dc,true);\n        const float opacity = (float)_mp_arg(17);\n\n        if (mp.opcode[18]!=~0U) { // Opacity mask specified","sourceCodeStart":30149,"sourceCodeEnd":30185,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L30149-L30185","documentation":"CImg's math-parser 'draw()' opcode validates the target image vector against the user-supplied geometry (w,h,d,s). When the vector's element count (sizD) is smaller than w*h*d*s, it cannot be reshaped into the requested geometry, so CImgArgumentException is thrown to prevent out-of-bounds access.","triggerScenarios":"Calling draw(...) in a CImg math expression/formula where the target vector has fewer values than the product of the specified dimensions w*h*d*s (e.g. draw with target geometry 4x4 but a 8-element vector).","commonSituations":"Hand-written math_parser expressions with mismatched dimension arguments; dynamically computed sizes that under-run the declared geometry; porting scripts between image sizes without updating geometry constants.","solutions":["Increase the target vector so it contains at least w*h*d*s values, or","Reduce the specified geometry (w,h,d,s) so its product does not exceed the vector size sizD","Verify sizes at runtime with .size() before invoking draw() in the expression"],"exampleFix":"// before\ndraw(ind,vec_target,4,4,1,1,...); // target has 8 values\n// after\ndraw(ind,vec_target,2,4,1,1,...); // geometry matches 8-value vector","handlingStrategy":"validation","validationCode":"if (target.size() < (unsigned long)w*h*d*s) { /* fix geometry or vector */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute geometry from the vector's actual size instead of hard-coding","Assert vector.size() >= w*h*d*s before building draw() expressions","Centralize dimension constants shared between vector creation and draw() calls"],"tags":["cimg","image-processing","argument-validation","math-parser"],"backgroundTag":"tensor-shape-mismatch","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"}