{"record":{"id":"678c8857ea55ac67","repo":"Yalantis/uCrop","slug":"cimg-appname-math-parser-cimg-s-s-s-speci-678c88","errorCode":null,"errorMessage":"[cimg_appname_math_parser] CImg<%s>::%s: %s: Specified variable size %g is larger than %d.","messagePattern":"\\[cimg_appname_math_parser\\] CImg<(.+?)>::(.+?): (.+?): Specified variable size %g is larger than (.+?)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":21996,"sourceCode":"            if (!std::strncmp(ss,\"get(\",4)) { // Get value from external variable\n              _cimg_mp_op(\"Function 'get()'\");\n              s1 = ss4; while (s1<se1 && (*s1!=',' || level[s1 - expr._data]!=clevel1)) ++s1;\n              arg1 = compile(ss4,s1,depth1,0,block_flags);\n              arg2 = arg3 = 0;\n              if (s1<se1) {\n                s2 = ++s1; while (s2<se1 && (*s2!=',' || level[s2 - expr._data]!=clevel1)) ++s2;\n                arg2 = compile(s1,s2,depth1,0,block_flags);\n                arg3 = s2<se1?compile(++s2,se1,depth1,0,block_flags):0;\n              }\n              _cimg_mp_check_type(arg1,1,2,0);\n              _cimg_mp_check_const_scalar(arg2,2,2);\n              _cimg_mp_check_type(arg3,3,1,0);\n              p1 = size(arg1);\n\n              const int siz_max = cimg::type<int>::max();\n              if (mem[arg2]>=siz_max) {\n                _cimg_mp_strerr;\n                throw CImgArgumentException(\"[\" cimg_appname \"_math_parser] \"\n                                            \"CImg<%s>::%s: %s: Specified variable size %g is larger than %d.\",\n                                            pixel_type(),_cimg_mp_calling_function,s_op,\n                                            mem[arg2],siz_max);\n              }\n              arg2 = (unsigned int)mem[arg2];\n              if (arg2) pos = vector(arg2); else pos = scalar();\n              CImg<ulongT>::vector((ulongT)mp_get,pos,arg1,p1,arg2,arg3).move_to(code);\n              return_comp = true;\n              _cimg_mp_return(pos);\n            }\n#endif\n            break;\n\n          case 'h' :\n            if (*ss1=='(') { // Image height\n              _cimg_mp_op(\"Function 'h()'\");\n              if (*ss2=='#') { // Index specified\n                p1 = compile(ss3,se1,depth1,0,block_flags);","sourceCodeStart":21978,"sourceCodeEnd":22014,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L21978-L22014","documentation":"When a math-parser function (e.g. dynamic vector allocation like `vector(size)`) computes the requested size at runtime, the resulting value must fit in an int. If mem[arg2] (the evaluated size, stored as double) exceeds cimg::type<int>::max(), CImg throws this error instead of truncating or overflowing the allocation.","triggerScenarios":"Calling `vector(n)` / `array(n)` style allocation where the size expression evaluates to a value >= 2^31-1, e.g. `vector(2^31)` or a size computed from image dimensions with an off-by-scale multiplication; NaN/negative values may also produce out-of-range comparisons leading here.","commonSituations":"Computing vector sizes from large image dimensions without clamping; unit confusion (bytes vs elements) inflating the requested size; unbounded loop-generated sizes in generated expressions.","solutions":["Clamp or reduce the requested size expression so it is < 2147483647","Verify units: the argument is the number of elements, not bytes","Add a runtime guard in the expression (e.g. `min(size, 1e9)`) before allocating","Rework the algorithm: a >2G-element per-item buffer usually indicates a logic bug"],"exampleFix":"// before\nimg.fill(\"n = w*h*d; v = vector(n)\"); // may exceed int max\n// after\nimg.fill(\"n = min(w*h*d,2e9); v = vector(n)\");","handlingStrategy":"validation","validationCode":"long n = (long) width * height * depth; // or whatever drives the size\nif (n <= 0 || n >= Integer.MAX_VALUE) throw new IllegalArgumentException(\"Requested vector size out of int range: \" + n);","typeGuard":null,"tryCatchPattern":"try { img.fill(expr); } catch (CImgArgumentException e) { if (e.getMessage().contains(\"Specified variable size\")) { /* clamp size and retry, or fail fast */ } throw e; }","preventionTips":["Clamp computed sizes with min() in the expression","Remember sizes are element counts, not bytes","Sanity-check sizes derived from image dimensions before allocating"],"tags":["cimg","math-parser","allocation","size-limit"],"backgroundTag":"value-out-of-range","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"}