| author | |
| committer | |
| log | 41430a366f75eb7301deaca91d4aea3bbf61c8ec |
| tree | bf2c9415996623fa9b9d41329ce0dcb3631d3b22 |
| parent | c16d4ab9e41be6b5c560d15eaa145ff3a0ffce6c |
Previously, the buffer reserved with `retain_with_limit` was missing
space for the `BufNode`.
When the user-provided a limit that was smaller than `@sizeOf(BufNode)`,
`reset` would store a new `BufNode` in an allocation smaller than
`BufNode`, leading to a buffer overrun.1 files changed, 1 insertions(+), 1 deletions(-)
lib/std/heap/arena_allocator.zig+1-1| ... | ... | @@ -120,7 +120,7 @@ pub const ArenaAllocator = struct { |
| 120 | 120 | } |
| 121 | 121 | const total_size = switch (mode) { |
| 122 | 122 | .retain_capacity => current_capacity, |
| 123 | .retain_with_limit => |limit| std.math.min(limit, current_capacity), | |
| 123 | .retain_with_limit => |limit| std.math.min(@sizeOf(BufNode) + limit, current_capacity), | |
| 124 | 124 | .free_all => unreachable, |
| 125 | 125 | }; |
| 126 | 126 | const align_bits = std.math.log2_int(usize, @alignOf(BufNode)); |