hsdfat commented on code in PR #12215:
URL: https://github.com/apache/arrow-rs/pull/12215#discussion_r4559249188
##########
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:
Applied in 26e8475, thanks.
##########
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:
Applied in 26e8475, thanks.
##########
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 would rather keep them, unless a committer prefers otherwise. There is one
per decoder because the two `read` paths are separate code, and they are what
shows the wrap on a 32-bit target (I ran them on `i686-unknown-linux-gnu`,
where they fail without the change). On 64-bit they pass either way, so they
cost little, but I am fine with dropping to one if you feel strongly.
--
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]