mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 21:22:43 -06:00
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.