zhangxinyao88 commented on code in PR #10923:
URL: https://github.com/apache/arrow-rs/pull/10923#discussion_r3899530134
##########
arrow-avro/src/reader/record.rs:
##########
@@ -733,9 +718,9 @@ impl Decoder {
| Self::Array(_, offsets, _)
| Self::Map(_, _, offsets, _, _) => {
offsets.reserve(count);
- for _ in 0..count {
- offsets.push_length(0);
- }
+ let offset = *offsets.last().expect("offsets cannot be empty");
+ let new_len =
offsets.len().checked_add(count).expect("overflow");
+ offsets.resize(new_len, offset);
Review Comment:
Fixed in `ef721fe4e`. I removed the extra `reserve`, and `new_len` overflow
now returns `AvroError::ParseError` instead of panicking.
##########
arrow-avro/src/reader/record.rs:
##########
@@ -2397,8 +2382,32 @@ fn flush_values<T>(values: &mut Vec<T>) -> Vec<T> {
}
#[inline]
-fn flush_offsets(offsets: &mut OffsetBufferBuilder<i32>) -> OffsetBuffer<i32> {
- std::mem::replace(offsets,
OffsetBufferBuilder::new(DEFAULT_CAPACITY)).finish()
+fn new_offsets() -> Vec<i32> {
+ let mut offsets = Vec::with_capacity(DEFAULT_CAPACITY + 1);
+ offsets.push(0);
+ offsets
+}
+
+#[inline]
+fn push_offset(offsets: &mut Vec<i32>, offset: usize) {
+ let offset = i32::try_from(offset).expect("overflow");
+ debug_assert!(offset >= *offsets.last().expect("offsets cannot be empty"));
+ offsets.push(offset);
+}
+
+#[inline]
+fn push_length(offsets: &mut Vec<i32>, length: usize) {
+ let length = i32::try_from(length).expect("overflow");
+ let last = *offsets.last().expect("offsets cannot be empty");
+ offsets.push(last.checked_add(length).expect("overflow"));
+}
Review Comment:
Fixed in `ef721fe4e`. The helpers return `Result` now, and both conversion
and addition overflow are reported as `AvroError::ParseError`. I added a small
test for both cases.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]