Skip to content

Commit b3de3bb

Browse files
Remove UB in aligned_vector
1 parent 4d7d103 commit b3de3bb

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

zk_ee/src/utils/aligned_vector.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ impl<A: Allocator> UsizeAlignedByteBox<A> {
120120
alloc::boxed::Box::new_uninit_slice_in(buffer_size, allocator);
121121
let written_words = init_fn(&mut inner);
122122
assert!(written_words <= buffer_size); // we do not want to truncate or realloc, but we will expose only written part below
123+
// Safety: init_fn only guarantees that it initialized `written_words` elements.
124+
// Initialize the remainder to avoid UB in assume_init().
125+
for dst in inner.iter_mut().skip(written_words) {
126+
dst.write(0);
127+
}
123128
let byte_capacity = written_words * USIZE_SIZE; // we only count initialized words for capacity purposes
124129

125130
Self {

0 commit comments

Comments
 (0)