Skip to content

Commit 7bce3b1

Browse files
committed
prevent modifying vector after in-place conversion to string
part of #24388
1 parent 7a44c04 commit 7bce3b1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/array.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,11 @@ JL_DLLEXPORT jl_value_t *jl_array_to_string(jl_array_t *a)
441441
if (jl_is_string(o)) {
442442
a->flags.isshared = 1;
443443
*(size_t*)o = jl_array_len(a);
444+
a->nrows = 0;
445+
#ifdef STORE_ARRAY_LEN
446+
a->length = 0;
447+
#endif
448+
a->maxsize = 0;
444449
return o;
445450
}
446451
}

test/strings/basic.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,3 +810,11 @@ let s = "∀x∃y", u = codeunits(s)
810810
@test_throws ErrorException (u[1] = 0x00)
811811
@test collect(u) == b"∀x∃y"
812812
end
813+
814+
# issue #24388
815+
let v = unsafe_wrap(Vector{UInt8}, "abc")
816+
s = String(v)
817+
@test_throws BoundsError v[1]
818+
push!(v, UInt8('x'))
819+
@test s == "abc"
820+
end

0 commit comments

Comments
 (0)