Repository navigation
Commit ca68232
fix(buffer): don't create &mut [u64] over uninitialized memory in collect_words_in (#10294)
`BitBufferMut::collect_words_in` allocated with `with_capacity_in`,
called `set_len` to claim the memory was initialised, and passed
`as_mut_slice()` to the fill closure. That creates a `&mut [u64]` over
uninitialised memory before anything writes to it. The safety comment
argued this was fine because `fill` writes every word and `u64` has no
invalid bit patterns, but a reference to uninitialised memory is UB on
its own.
This uses `BufferMut::zeroed_in(num_words, allocator)` instead, keeping
the allocator. `fill` still overwrites every word, so the only extra
cost is one memset.
### Testing
- Behaviour is unchanged and already covered by the existing
`BitBufferMut` tests; I didn't add a new one.
- `cargo test -p vortex-buffer --all-features`, clippy, nightly fmt, and
Miri on `bit::buf_mut` with CI's `MIRIFLAGS`.
### AI assistance
This change was prepared with help from an AI coding assistant
(Google-internal agentic tooling). I reviewed and verified the change
and the tests myself.
Signed-off-by: Jian He <hejia@google.com>
Co-authored-by: Jian He <hejia@google.com>1 parent 5a6de2b commit ca68232
1 file changed
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
270 | 270 | | |
271 | 271 | | |
272 | 272 | | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
| |||
0 commit comments