You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/01/08 11:56:26 UTC
[GitHub] [arrow-rs] alamb opened a new issue #1144: Undefined behavior for GenericStringArray::from_iter_values if reported iterator upper bound is incorrect
alamb opened a new issue #1144:
URL: https://github.com/apache/arrow-rs/issues/1144
**Describe the bug**
While reviewing #197 I was able to create a reproducer that indeed caused undefined behavior
**To Reproduce**
```rust
use arrow::array::StringArray;
// Make an iterator that is untruthful about its actual length (say it is shorter than it really is):
#[derive(Debug, Clone)]
struct BadIterator<T> {
/// where the iterator currently is
cur: u64,
/// How many items will this iterator *actually* make
limit: u64,
/// How many items this iterator claims it will make
claimed: u64,
/// What type of item to return
pub item: T,
}
impl<T> BadIterator<T> {
/// Create a new iterator for <limit> items, but that reports to
/// produce <claimed> items
fn new(limit: u64, claimed: u64, item: T) -> Self {
Self{
cur: 0,
limit,
claimed,
item
}
}
}
impl <T:Clone> Iterator for BadIterator<T> {
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
if self.cur < self.limit {
self.cur += 1;
Some(self.item.clone())
} else {
None
}
}
/// report whatever the iterator says to
fn size_hint(&self) -> (usize, Option<usize>) {
(0, Some(self.claimed as usize))
}
}
fn from_vec(v: Vec<&str>) -> StringArray {
v.into_iter()
.map(Some)
.collect()
}
// This definitely causes a problem
fn use_iter_values() {
// correctly report size:
let array = StringArray::from_iter_values(BadIterator::new(3, 3, "foo"));
assert_eq!(array, from_vec(vec!["foo", "foo", "foo"]));
// incorrectly correctly report size to be 10
let array = StringArray::from_iter_values(BadIterator::new(3, 10, "foo"));
assert_eq!(array, from_vec(vec!["foo", "foo", "foo"]));
// incorrectly correctly report size to be 1 (too small)
let array = StringArray::from_iter_values(BadIterator::new(3, 1, "foo"));
assert_eq!(array, from_vec(vec!["foo", "foo", "foo"]));
}
fn main() {
println!("Starting...");
use_iter_values();
println!("Done...");
}
```
Results in
```
Starting...
Use collect
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /Users/alamb/Software/arrow-rs/arrow/src/array/array_string.rs:101:40
stack backtrace:
```
And undefined behavior in MIRI
**Expected behavior**
Success and no undefined behavior
**Additional context**
Add any other context about the problem here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] alamb commented on issue #1144: Undefined behavior for GenericStringArray::from_iter_values if reported iterator upper bound is incorrect
Posted by GitBox <gi...@apache.org>.
alamb commented on issue #1144:
URL: https://github.com/apache/arrow-rs/issues/1144#issuecomment-1007970802
It looks like `DataFusion` uses `from_iter_values` in several places (both for StringArrays and primitive arrays)
https://github.com/apache/arrow-datafusion/search?q=from_iter_values
However, when I was looking at the implementations of `FromIterator` and `from_iter_values` I didn't see the need for both.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] jorgecarleitao commented on issue #1144: Undefined behavior for GenericStringArray::from_iter_values if reported iterator upper bound is incorrect
Posted by GitBox <gi...@apache.org>.
jorgecarleitao commented on issue #1144:
URL: https://github.com/apache/arrow-rs/issues/1144#issuecomment-1008153443
> Strangely, I don't understand the usecase of from_iter_values compared to `FromIterator`
I think that `from_iter_values` leverages the invariant that there are no nulls in the iterator (`AsRef<str>`), while `FromIterator` accepts nulls / None. The two APIs are motivated by a significant performance penalty in creating the bitmap from an iterator of options (compared to the cost of an iterator of non-nullable values)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] alamb commented on issue #1144: Undefined behavior for GenericStringArray::from_iter_values if reported iterator upper bound is incorrect
Posted by GitBox <gi...@apache.org>.
alamb commented on issue #1144:
URL: https://github.com/apache/arrow-rs/issues/1144#issuecomment-1007969914
Strangely, I don't understand the usecase of from_iter_values compared to `FromIter` -- I'll add a PR to remove the API
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] alamb edited a comment on issue #1144: Undefined behavior for GenericStringArray::from_iter_values if reported iterator upper bound is incorrect
Posted by GitBox <gi...@apache.org>.
alamb edited a comment on issue #1144:
URL: https://github.com/apache/arrow-rs/issues/1144#issuecomment-1007969914
Strangely, I don't understand the usecase of from_iter_values compared to `FromIterator`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] alamb closed issue #1144: Undefined behavior for GenericStringArray::from_iter_values if reported iterator upper bound is incorrect
Posted by GitBox <gi...@apache.org>.
alamb closed issue #1144:
URL: https://github.com/apache/arrow-rs/issues/1144
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] alamb edited a comment on issue #1144: Undefined behavior for GenericStringArray::from_iter_values if reported iterator upper bound is incorrect
Posted by GitBox <gi...@apache.org>.
alamb edited a comment on issue #1144:
URL: https://github.com/apache/arrow-rs/issues/1144#issuecomment-1007969914
Strangely, I don't understand the usecase of from_iter_values compared to `FromIter`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org