Skip to content

Commit

Permalink
Fix zero-length array concatenation validation (#45383)
Browse files Browse the repository at this point in the history
(cherry picked from commit 0a55a8e)
  • Loading branch information
BioTurboNick authored and KristofferC committed Jun 7, 2022
1 parent b6e47d4 commit d6bbed6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@ function _typed_hvncat_shape(::Type{T}, shape::NTuple{N, Tuple}, row_first, as::
shapelength == lengthas || throw(ArgumentError("number of elements does not match shape; expected $(shapelength), got $lengthas)"))
# discover dimensions
nd = max(N, cat_ndims(as[1]))
outdims = zeros(Int, nd)
outdims = fill(-1, nd)
currentdims = zeros(Int, nd)
blockcounts = zeros(Int, nd)
shapepos = ones(Int, nd)
Expand All @@ -2503,7 +2503,7 @@ function _typed_hvncat_shape(::Type{T}, shape::NTuple{N, Tuple}, row_first, as::

isendblock = blockcounts[d] == shapev[d][shapepos[d]]
if isendblock
if outdims[d] == 0
if outdims[d] == -1
outdims[d] = currentdims[d]
elseif outdims[d] != currentdims[d]
throw(ArgumentError("argument $i has a mismatched number of elements along axis $ad; \
Expand Down
4 changes: 1 addition & 3 deletions test/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1465,9 +1465,7 @@ using Base: typed_hvncat
v1 = zeros(Int, 0, 0, 0)
for v2 (1, [1])
for v3 (2, [2])
# current behavior, not potentially dangerous.
# should throw error like above loop
@test [v1 ;;; v2 v3] == [v2 v3;;;]
@test_throws ArgumentError [v1 ;;; v2 v3]
@test_throws ArgumentError [v1 ;;; v2]
@test_throws ArgumentError [v1 v1 ;;; v2 v3]
end
Expand Down

0 comments on commit d6bbed6

Please sign in to comment.