Files
opencv-MIRROR/modules
Abhishek Gola a282408291 Merge pull request #31307 from ish1416/fix-gather2-int64-bounds-5x
Problem
In gather2_layer.cpp, CPU gather() casts CV_64S indices to 32-bit int before bounds checking (int k = ind32 ? (int)ind32[j] : (int)ind64[j]), so out-of-range 64-bit indices such as 1LL << 32 or (1LL << 32) - 1 silently truncate to 0 or -1 and gather valid slices instead of raising Error::StsOutOfRange (unlike CUDA GatherOp, which already validates in int64_t). Related to the Gather2 note in #30575.

The error flag volatile bool globOutOfRangeIdx is also shared across parallel_for_ threads without atomicity, and the index bounds check ran inside the nslices loop.

Fix
Keep k and shape_a in int64_t, hoist negative-index normalization and bounds validation out of the nslices loop, guard memcpy on sliceSize > 0, and use std::atomic<bool> for globOutOfRangeIdx. Added regression test Layer_Test_Gather2.Int64IndexBoundsCheck.
2026-12-02 18:15:55 +05:30
..
2026-12-01 23:18:38 +05:30