You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use the capacity from the entities Vec to initialize Table columns (#20528)
# Objective
When working with `realloc`, it's a safety invariant to pass in the
existing layout of the allocation that is being reallocated. This may
not be the case with newly created `Table`s. `Vec::with_capacity`'s
documentation states that it will return an allocation with enough space
for *at least* `capacity` elements, not exactly `capacity`. This means
that `entities.capacity()` may be greater than the provided capacity. As
the `ThinColumn`s use this as their capacity, the new Layout fed to
`realloc` will not match the allocation originally provided to `alloc`.
This is unsound.
While investigating this, I also found that we were not validating that
the total capacity of `BlobArray`'s layout upon reallocation were less
than `isize::MAX` via `array_layout_unchecked`.
## Solution
Begin `Table` construction by allocating the `entities` Vec, and use
it's capacity to allocate the columns instead of directly feeding the
provided capacity into `ThinColumn::with_capacity`.
Replace the `array_layout_unchecked` call with a safe call to
`array_layout`, and panic if it fails.
## Testing
Tested this locally against existing unit tests and miri.
---------
Co-authored-by: Giacomo Stevanato <[email protected]>
0 commit comments