Files
opencv-MIRROR/modules/core
Abhishek Gola 24d37ecc01 Merge pull request #31291 from poojithparchuri-iiitk/mat-negative-size
Why
In 4.x, setSize has CV_Assert( s >= 0 ) for every dimension. On 5.x, setSize copies the sizes into a MatShape and the check is gone. Mat::create then leaves a matrix without memory and the caller writes into it. I did not find an issue or PR about this.

What I changed
The same check in setSize, with a guard for a null pointer, as 4.x did (5 lines). A size of 0 is still allowed. I added two tests: Core_Mat.create_negative_size (Mat::create and the Mat constructor) and Imgproc_Hist_Calc.regression_negative_hist_size (calcHist with negative bins in 1D, 2D and with a mask, and a normal call afterwards).
2026-12-02 11:33:39 +05:30
..