diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2024-04-08 12:44:42 -0400 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2024-04-08 13:24:08 -0400 |
| commit | 7611d90ba011fb030523e669e85acfb6faae5d19 (patch) | |
| tree | f1b48f3ac73681c402dce10b5857ecc0f84dd7a4 /src/mutable_value.zig | |
| parent | 4cd92567e7392b0fe390562d7ea52f68357bb45a (diff) | |
| download | zig-7611d90ba011fb030523e669e85acfb6faae5d19.tar.gz zig-7611d90ba011fb030523e669e85acfb6faae5d19.zip | |
InternPool: remove slice from byte aggregate keys
This deletes a ton of lookups and avoids many UAF bugs.
Closes #19485
Diffstat (limited to 'src/mutable_value.zig')
| -rw-r--r-- | src/mutable_value.zig | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/mutable_value.zig b/src/mutable_value.zig index 327c354108..f16a8fd3f9 100644 --- a/src/mutable_value.zig +++ b/src/mutable_value.zig @@ -73,7 +73,7 @@ pub const MutableValue = union(enum) { } }), .bytes => |b| try ip.get(gpa, .{ .aggregate = .{ .ty = b.ty, - .storage = .{ .bytes = b.data }, + .storage = .{ .bytes = try ip.getOrPutString(gpa, b.data, .maybe_embedded_nulls) }, } }), .aggregate => |a| { const elems = try arena.alloc(InternPool.Index, a.elems.len); @@ -158,18 +158,18 @@ pub const MutableValue = union(enum) { }, .aggregate => |agg| switch (agg.storage) { .bytes => |bytes| { - assert(bytes.len == ip.aggregateTypeLenIncludingSentinel(agg.ty)); + const len: usize = @intCast(ip.aggregateTypeLenIncludingSentinel(agg.ty)); assert(ip.childType(agg.ty) == .u8_type); if (allow_bytes) { - const arena_bytes = try arena.alloc(u8, bytes.len); - @memcpy(arena_bytes, bytes); + const arena_bytes = try arena.alloc(u8, len); + @memcpy(arena_bytes, bytes.toSlice(len, ip)); mv.* = .{ .bytes = .{ .ty = agg.ty, .data = arena_bytes, } }; } else { - const mut_elems = try arena.alloc(MutableValue, bytes.len); - for (bytes, mut_elems) |b, *mut_elem| { + const mut_elems = try arena.alloc(MutableValue, len); + for (bytes.toSlice(len, ip), mut_elems) |b, *mut_elem| { mut_elem.* = .{ .interned = try ip.get(gpa, .{ .int = .{ .ty = .u8_type, .storage = .{ .u64 = b }, |
