Skip to content

Commit 05a7e48

Browse files
vtjnashKristofferC
authored andcommitted
stacktrace: prevent OOB-error in sysimage lookup (#30369)
Previously, with a multi-versioned system image, there might be additional entries at the end of the clone list that do not correspond to an actual method (such as jlplt thunks). Also some code cleanup for clarity. fix #28648 (cherry picked from commit e51a707)
1 parent 776a251 commit 05a7e48

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/debuginfo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,8 @@ static int jl_getDylibFunctionInfo(jl_frame_t **frames, size_t pointer, int skip
11011101
for (size_t i = 0; i < sysimg_fptrs.nclones; i++) {
11021102
if (diff == sysimg_fptrs.clone_offsets[i]) {
11031103
uint32_t idx = sysimg_fptrs.clone_idxs[i] & jl_sysimg_val_mask;
1104-
frame0->linfo = sysimg_fvars_linfo[idx];
1104+
if (idx < sysimg_fvars_n) // items after this were cloned but not referenced directly by a method (such as our ccall PLT thunks)
1105+
frame0->linfo = sysimg_fvars_linfo[idx];
11051106
break;
11061107
}
11071108
}

src/staticdata.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ static void jl_update_all_fptrs(jl_serializer_state *s)
10151015
for (i = 0; i < sysimg_fvars_max; i++) {
10161016
uintptr_t val = (uintptr_t)&linfos[i];
10171017
uint32_t offset = load_uint32(&val);
1018+
linfos[i] = NULL;
10181019
if (offset != 0) {
10191020
int specfunc = 1;
10201021
if (offset & ((uintptr_t)1 << (8 * sizeof(uint32_t) - 1))) {

stdlib/Profile/src/Profile.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ function tree!(root::StackFrameTree{T}, all::Vector{UInt64}, lidict::Union{LineI
514514
# jump forward to the end of the inlining chain
515515
# avoiding an extra (slow) lookup of `ip` in `lidict`
516516
# and an extra chain of them in `down`
517+
# note that we may even have this === parent (if we're ignoring this frame ip)
517518
this = builder_value[fastkey]
518519
let this = this
519520
while this !== parent
@@ -532,8 +533,7 @@ function tree!(root::StackFrameTree{T}, all::Vector{UInt64}, lidict::Union{LineI
532533
frame = (frames isa Vector ? frames[i] : frames)
533534
!C && frame.from_c && continue
534535
key = (T === UInt64 ? ip : frame)
535-
down = parent.down
536-
this = get!(down, key) do
536+
this = get!(parent.down, key) do
537537
return StackFrameTree{T}()
538538
end
539539
this.frame = frame

0 commit comments

Comments
 (0)