Skip to content

Commit eb401f3

Browse files
committed
Make loading fail if it detects a buildid collision
1 parent 57a1d3a commit eb401f3

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/staticdata.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4410,7 +4410,11 @@ static jl_value_t *jl_restore_package_image_from_stream(ios_t *f, jl_image_t *im
44104410
JL_SIGATOMIC_END();
44114411

44124412
// Add roots to methods
4413-
jl_copy_roots(method_roots_list, jl_worklist_key((jl_array_t*)restored));
4413+
int failed = jl_copy_roots(method_roots_list, jl_worklist_key((jl_array_t*)restored));
4414+
if (failed != 0) {
4415+
jl_printf(JL_STDERR, "Error copying roots to methods from Module: %s\n", pkgname);
4416+
abort();
4417+
}
44144418
// Insert method extensions and handle edges
44154419
int new_methods = jl_array_nrows(extext_methods) > 0;
44164420
if (!new_methods) {

src/staticdata_utils.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,17 +736,31 @@ static void jl_activate_methods(jl_array_t *external, jl_array_t *internal, size
736736
}
737737
}
738738

739-
static void jl_copy_roots(jl_array_t *method_roots_list, uint64_t key)
739+
static int jl_copy_roots(jl_array_t *method_roots_list, uint64_t key)
740740
{
741741
size_t i, l = jl_array_nrows(method_roots_list);
742+
int failed = 0;
742743
for (i = 0; i < l; i+=2) {
743744
jl_method_t *m = (jl_method_t*)jl_array_ptr_ref(method_roots_list, i);
744745
jl_array_t *roots = (jl_array_t*)jl_array_ptr_ref(method_roots_list, i+1);
745746
if (roots) {
746747
assert(jl_is_array(roots));
748+
if (m->root_blocks) {
749+
// check for key collision
750+
uint64_t *blocks = jl_array_data(m->root_blocks, uint64_t);
751+
size_t nx2 = jl_array_nrows(m->root_blocks);
752+
for (size_t i = 0; i < nx2; i+=2) {
753+
if (blocks[i] == key) {
754+
// found duplicate block
755+
failed = -1;
756+
}
757+
}
758+
}
759+
747760
jl_append_method_roots(m, key, roots);
748761
}
749762
}
763+
return failed;
750764
}
751765

752766
static jl_value_t *read_verify_mod_list(ios_t *s, jl_array_t *depmods)

0 commit comments

Comments
 (0)