diff --git a/src/array.c b/src/array.c index 746d474b97b18..6a893f96cf43e 100644 --- a/src/array.c +++ b/src/array.c @@ -61,8 +61,9 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims, jl_array_t *a; for(i=0; i < ndims; i++) { - wideint_t prod = (wideint_t)nel * (wideint_t)dims[i]; - if (prod > (wideint_t) MAXINTVAL) + size_t di = dims[i]; + wideint_t prod = (wideint_t)nel * (wideint_t)di; + if (prod > (wideint_t) MAXINTVAL || di > MAXINTVAL) jl_error("invalid Array dimensions"); nel = prod; } diff --git a/test/core.jl b/test/core.jl index d8981f352ffb1..822fa6fca76c7 100644 --- a/test/core.jl +++ b/test/core.jl @@ -6697,3 +6697,8 @@ function repackage28445() true end @test repackage28445() + +# issue #28597 +@test_throws ErrorException Array{Int, 2}(undef, 0, -10) +@test_throws ErrorException Array{Int, 2}(undef, -10, 0) +@test_throws ErrorException Array{Int, 2}(undef, -1, -1)