Skip to content

Commit e51a707

Browse files
authored
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
1 parent 36cc20c commit e51a707

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
@@ -1087,7 +1087,8 @@ static int jl_getDylibFunctionInfo(jl_frame_t **frames, size_t pointer, int skip
10871087
for (size_t i = 0; i < sysimg_fptrs.nclones; i++) {
10881088
if (diff == sysimg_fptrs.clone_offsets[i]) {
10891089
uint32_t idx = sysimg_fptrs.clone_idxs[i] & jl_sysimg_val_mask;
1090-
frame0->linfo = sysimg_fvars_linfo[idx];
1090+
if (idx < sysimg_fvars_n) // items after this were cloned but not referenced directly by a method (such as our ccall PLT thunks)
1091+
frame0->linfo = sysimg_fvars_linfo[idx];
10911092
break;
10921093
}
10931094
}

src/staticdata.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@ static void jl_update_all_fptrs(jl_serializer_state *s)
10161016
for (i = 0; i < sysimg_fvars_max; i++) {
10171017
uintptr_t val = (uintptr_t)&linfos[i];
10181018
uint32_t offset = load_uint32(&val);
1019+
linfos[i] = NULL;
10191020
if (offset != 0) {
10201021
int specfunc = 1;
10211022
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)