Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #581, report dangerous indexing #582

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/analyzers/jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,14 @@ function report_serious_exception!(analyzer::JETAnalyzer, sv::InferenceState, ar
return true
end
end
elseif widenconst(a) <: ArgumentError
# promote `ArgumentError` thrown by `to_index` method
# so that we get reports from dangerous indexing (aviatesk/JET.jl#581)
def = sv.linfo.def
if isa(def, Method) && def.name === :to_index
add_new_report!(analyzer, sv.result, SeriousExceptionReport(sv, ArgumentError("invalid index"), get_lin((sv, get_currpc(sv)))))
return true
end
end
end
return false
Expand Down
15 changes: 15 additions & 0 deletions test/analyzers/test_jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,21 @@ end
end
end

func_invalid_index(xs, i) = xs[i]
func_invalid_index(xs::Vector{Int}) = xs[findfirst(>(0), xs)]
@testset "report invalid index" begin
let result = report_call(func_invalid_index, (Vector{Int},Nothing))
@test count(get_reports_with_test(result)) do r
r isa SeriousExceptionReport
end == 1
end
let result = report_call(func_invalid_index, (Vector{Int},))
@test count(get_reports_with_test(result)) do r
r isa SeriousExceptionReport
end == 1
end
end

@testset "DivideError" begin
let result = report_call() do
div(1, 0)
Expand Down
Loading