Rich-T-kid commented on code in PR #12215:
URL: https://github.com/apache/arrow-rs/pull/12215#discussion_r4554992523
##########
parquet/src/arrow/array_reader/byte_array.rs:
##########
@@ -390,10 +390,12 @@ impl ByteArrayDecoderPlain {
let len = u32::from_le_bytes(len_bytes);
let start_offset = self.offset + 4;
- let end_offset = start_offset + len as usize;
- if end_offset > buf.len() {
- return Err(ParquetError::EOF("eof decoding byte
array".into()));
- }
+ // `checked_add` because the length comes from the page: on a
32-bit
+ // target a corrupt one could wrap `end_offset` below
`start_offset`.
+ let end_offset = start_offset
+ .checked_add(len as usize)
+ .filter(|&end| end <= buf.len())
+ .ok_or_else(|| ParquetError::EOF("eof decoding byte
array".into()))?;
Review Comment:
```suggestion
let end_offset = start_offset
.checked_add(len as usize)
.filter(|&end| end <= buf.len())
.ok_or_else(|| ParquetError::EOF("eof decoding byte
array".into()))?;
```
##########
parquet/src/arrow/array_reader/byte_view_array.rs:
##########
@@ -835,6 +837,22 @@ mod tests {
assert_eq!(view_buffer.buffers.len(), 1);
}
+ #[test]
Review Comment:
I think we can remove the test, the change is straightforward enough to not
warrant them.
maybe just one if we are very adamant about it
##########
parquet/src/arrow/array_reader/byte_view_array.rs:
##########
@@ -364,11 +364,13 @@ impl ByteViewArrayDecoderPlain {
.unwrap(),
);
- end_offset = start_offset + len as usize;
-
- if end_offset > buf_len {
- return Err(ParquetError::EOF("eof decoding byte
array".into()));
- }
+ // `checked_add` because the length comes from the page: on a
32-bit
+ // target a corrupt one could wrap `end_offset` below
`start_offset`
+ // and pass the bounds check below.
+ end_offset = start_offset
+ .checked_add(len as usize)
+ .filter(|&end| end <= buf_len)
+ .ok_or_else(|| ParquetError::EOF("eof decoding byte
array".into()))?;
Review Comment:
```suggestion
end_offset = start_offset
.checked_add(len as usize)
.filter(|&end| end <= buf_len)
.ok_or_else(|| ParquetError::EOF("eof decoding byte
array".into()))?;
```
--
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]