diff options
author | 2023-06-28 11:27:31 -0700 | |
---|---|---|
committer | 2023-06-28 11:27:31 -0700 | |
commit | 43752ec3f0fac7ffe790272ba5d0ebbbca02572c (patch) | |
tree | 1cf52b0cd6a887c8a2b539d82ec7685edf6a5463 /src | |
parent | e6e3d9e368919a8433243099d4ce8af01ad08bd9 (diff) | |
download | bun-43752ec3f0fac7ffe790272ba5d0ebbbca02572c.tar.gz bun-43752ec3f0fac7ffe790272ba5d0ebbbca02572c.tar.zst bun-43752ec3f0fac7ffe790272ba5d0ebbbca02572c.zip |
Fix assertion failure in escapeHTML with UTF-16 text (#3436)
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/string_immutable.zig | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/string_immutable.zig b/src/string_immutable.zig index 3931648b8..6c4eaa943 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -2488,11 +2488,11 @@ pub fn escapeHTMLForUTF16Input(allocator: std.mem.Allocator, utf16: []const u16) continue :scan_and_allocate_lazily; } - buf = try std.ArrayList(u16).initCapacity(allocator, utf16.len + 6); if (comptime Environment.allow_assert) std.debug.assert(@intFromPtr(remaining.ptr + i) >= @intFromPtr(utf16.ptr)); const to_copy = std.mem.sliceAsBytes(utf16)[0 .. @intFromPtr(remaining.ptr + i) - @intFromPtr(utf16.ptr)]; - @memcpy(@ptrCast([*]align(2) u8, buf.items[0..to_copy.len]), to_copy); - buf.items.len = std.mem.bytesAsSlice(u16, to_copy).len; + var to_copy_16 = std.mem.bytesAsSlice(u16, to_copy); + buf = try std.ArrayList(u16).initCapacity(allocator, utf16.len + 6); + try buf.appendSlice(to_copy_16); while (i < ascii_u16_vector_size) { switch (remaining[i]) { @@ -2603,13 +2603,8 @@ pub fn escapeHTMLForUTF16Input(allocator: std.mem.Allocator, utf16: []const u16) if (comptime Environment.allow_assert) std.debug.assert(@intFromPtr(ptr) >= @intFromPtr(utf16.ptr)); const to_copy = std.mem.sliceAsBytes(utf16)[0 .. @intFromPtr(ptr) - @intFromPtr(utf16.ptr)]; - - @memcpy( - @ptrCast([*]align(2) u8, buf.items[0..to_copy.len]), - to_copy, - ); - - buf.items.len = std.mem.bytesAsSlice(u16, to_copy).len; + var to_copy_16 = std.mem.bytesAsSlice(u16, to_copy); + try buf.appendSlice(to_copy_16); any_needs_escape = true; break :scan_and_allocate_lazily; }, |