Skip to content

Commit

Permalink
fix #31758: out of bounds write in sparse broadcast (#31763)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre authored Apr 19, 2019
1 parent 32b091b commit c0c6f96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/SparseArrays/src/higherorderfns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ function _map_zeropres!(f::Tf, C::SparseVecOrMat, As::Vararg{SparseVecOrMat,N})
vals, ks, rows = _fusedupdate_all(rowsentinel, activerow, rows, ks, stopks, As)
Cx = f(vals...)
if !_iszero(Cx)
Ck > spaceC && (spaceC = expandstorage!(C, Ck + min(length(C), _sumnnzs(As...)) - (sum(ks) - N)))
Ck > spaceC && (spaceC = expandstorage!(C, min(length(C), Ck + _sumnnzs(As...) - (sum(ks) - N))))
storedinds(C)[Ck] = activerow
storedvals(C)[Ck] = Cx
Ck += 1
Expand Down
10 changes: 10 additions & 0 deletions stdlib/SparseArrays/test/higherorderfns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,14 @@ end
@test w == bv .* op(av)
end

@testset "issue #31758: out of bounds write in _map_zeropres!" begin
y = sparsevec([2,7], [1., 2.], 10)
x1 = sparsevec(fill(1.0, 10))
x2 = sparsevec([2,7], [1., 2.], 10)
x3 = sparsevec(fill(1.0, 10))
f(x, y, z) = x == y == z == 0 ? 0.0 : NaN
y .= f.(x1, x2, x3)
@test all(isnan, y)
end

end # module

2 comments on commit c0c6f96

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.