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
{{ message }}
Repository navigation
String and BinaryArray created from iterators that don't accurately report size can lead to undefined behavior #197
The (Rust) Iterator spec recommends, but does not require, that the iterator reports a correct length. Consumer that lead to undefined behavior from an incorrect size_hint are the causers of said undefined behavior.
The only case where consumers can trust the iterators' length is when the interator implement unsafe trait TrustedLen. Unfortunately, TrustedLen is still in unstable. For that reason, we have been exposing unsafe Buffer::from_trusted_len_iter and the like for those cases.
So the code should be updated to handle the case where the reported size_hint turns out to be incorrect
Activity
alamb commentedon Jan 9, 2022
An update: manually audited all the uses of the
size_hintin the arrow codebase:My analysis is that any place where
upperis used to size a buffer, it is either:Vec::with_capacity) but not required for correctnessunsafeblock which clearly states it is undefined behavior to call the function with an iterator that does not correctly report its sizeGenericStringArray::from_iter_valuesif reported iterator upper bound is incorrect #1144For 2. above, the
unsafecode will panic if the iterator's size was inaccurate (potentially after writing past valid memory) as an additional safeguardThe only thing remaining for me to do on this issue is to verify the uses of the unsafe
from_trusted_itercalls.alamb commentedon Jan 11, 2022
As a final follow up, I did verify the uses of
from_trusted_iterin the crate and concluded they are all safe