Skip to content

Commit

Permalink
Ensure length(ipiv)==n before calling LAPACK.getrs! to avoid segfaults (
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindh-krishnamoorthy authored May 3, 2023
1 parent 404bb1f commit b66f63c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions stdlib/LinearAlgebra/src/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,9 @@ for (gels, gesv, getrs, getri, elty) in
if n != size(B, 1)
throw(DimensionMismatch("B has leading dimension $(size(B,1)), but needs $n"))
end
if n != length(ipiv)
throw(DimensionMismatch("ipiv has length $(length(ipiv)), but needs to be $n"))
end
nrhs = size(B, 2)
info = Ref{BlasInt}()
ccall((@blasfunc($getrs), libblastrampoline), Cvoid,
Expand Down
9 changes: 9 additions & 0 deletions stdlib/LinearAlgebra/test/lapack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -720,4 +720,13 @@ a = zeros(2,0), zeros(0)
@test LinearAlgebra.LAPACK.geqrf!(a...) === a
@test LinearAlgebra.LAPACK.gerqf!(a...) === a

# Issue #49489: https://github.com/JuliaLang/julia/issues/49489
# Dimension mismatch between A and ipiv causes segfaults
@testset "issue #49489" begin
A = randn(23,23)
b = randn(23)
ipiv = collect(1:20)
@test_throws DimensionMismatch LinearAlgebra.LAPACK.getrs!('N', A, ipiv, b)
end

end # module TestLAPACK

0 comments on commit b66f63c

Please sign in to comment.