{"record":{"id":"4408057df1ddc379","repo":"Yalantis/uCrop","slug":"data-invalid-pointer-request-at-coordinates","errorCode":null,"errorMessage":"data(): Invalid pointer request, at coordinates (%u,%u,%u,%u) [offset=%u].","messagePattern":"data\\(\\): Invalid pointer request, at coordinates \\(%u,%u,%u,%u\\) \\[offset=%u\\]\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":15421,"sourceCode":"\n    //! Return a pointer to a located pixel value.\n    /**\n       Return a \\c T*, or a \\c const \\c T* pointer to the value located at (\\c x,\\c y,\\c z,\\c c) in the pixel buffer\n       of the image instance,\n       whether the instance is \\c const or not.\n       \\param x X-coordinate of the pixel value.\n       \\param y Y-coordinate of the pixel value.\n       \\param z Z-coordinate of the pixel value.\n       \\param c C-coordinate of the pixel value.\n       \\note\n       - Writing \\c img.data(x,y,z,c) is equivalent to <tt>&(img(x,y,z,c))</tt>. Thus, this method has the same\n         properties as operator()(unsigned int,unsigned int,unsigned int,unsigned int).\n     **/\n#if cimg_verbosity>=3\n    T *data(const unsigned int x, const unsigned int y=0, const unsigned int z=0, const unsigned int c=0) {\n      const ulongT off = (ulongT)offset(x,y,z,c);\n      if (off>=size())\n        cimg::warn(_cimg_instance\n                   \"data(): Invalid pointer request, at coordinates (%u,%u,%u,%u) [offset=%u].\",\n                   cimg_instance,\n                   x,y,z,c,off);\n      return _data + off;\n    }\n\n    //! Return a pointer to a located pixel value \\const.\n    const T* data(const unsigned int x, const unsigned int y=0, const unsigned int z=0, const unsigned int c=0) const {\n      return const_cast<CImg<T>*>(this)->data(x,y,z,c);\n    }\n#else\n    T* data(const unsigned int x, const unsigned int y=0, const unsigned int z=0, const unsigned int c=0) {\n      return _data + x + (ulongT)y*_width + (ulongT)z*_width*_height + (ulongT)c*_width*_height*_depth;\n    }\n\n    const T* data(const unsigned int x, const unsigned int y=0, const unsigned int z=0, const unsigned int c=0) const {\n      return _data + x + (ulongT)y*_width + (ulongT)z*_width*_height + (ulongT)c*_width*_height*_depth;\n    }","sourceCodeStart":15403,"sourceCodeEnd":15439,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L15403-L15439","documentation":"CImg<T>::data(x,y,z,c) returns the raw pointer to the pixel at the given coordinates; in debug builds (cimg_verbosity>=3) it warns non-fatally when the computed offset is >= size(), i.e. the coordinates lie outside the image. Unlike operator(), it still returns the out-of-range pointer (_data+off), so the caller would silently read/write out-of-bounds memory unless the warning is heeded.","triggerScenarios":"Calling img.data(x,y,z,c) with coordinates beyond [width,height,depth,spectrum], or on an image whose allocation failed/zero-size while passing nonzero coordinates.","commonSituations":"Pointer-based pixel manipulation loops with wrong strides, passing pixel coordinates instead of channel-relative offsets, calling data() on a default-constructed CImg with nonzero coords.","solutions":["Validate x<img.width(), y<img.height(), z<img.depth(), c<img.spectrum() before calling data(x,y,z,c)","Use data() with no arguments to get the buffer start and index manually with checked offsets","Prefer operator()/at() accessors over raw pointers unless performance requires otherwise","Assert image non-emptiness and dimensions in debug builds before pointer arithmetic"],"exampleFix":"// before\nT* p = img.data(x, y); // x,y may exceed bounds\n// after\nif (x < img.width() && y < img.height()) { T* p = img.data(x, y); ... }","handlingStrategy":"type-guard","validationCode":"if (!(x < img.width() && y < img.height() && z < img.depth() && c < img.spectrum()))\n  throw std::out_of_range(\"data() request out of bounds\");","typeGuard":"template <typename T>\nT* safe_data(CImg<T>& img, unsigned x, unsigned y, unsigned z = 0, unsigned c = 0) {\n  if (x < img.width() && y < img.height() && z < img.depth() && c < img.spectrum())\n    return img.data(x, y, z, c);\n  return nullptr;\n}","tryCatchPattern":null,"preventionTips":["Check coordinates against width/height/depth/spectrum before requesting raw pointers","Call data() with no args and index manually with checked arithmetic","Assert dimensions in debug builds before pointer manipulation","Favor operator()/at() over raw pointers except in hot loops"],"tags":["bounds-check","pointer","pixel-access","out-of-bounds","cimg"],"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"}