Jefffrey commented on code in PR #11012:
URL: https://github.com/apache/arrow-rs/pull/11012#discussion_r4032588970
##########
arrow-ipc/src/reader.rs:
##########
@@ -4264,4 +4299,68 @@ mod tests {
"unexpected error: {err}"
);
}
+
+ fn file_with_declared_block(body_length: i64, meta_length: i32, offset:
i64) -> Vec<u8> {
+ let mut fbb = flatbuffers::FlatBufferBuilder::new();
+
+ let schema = crate::SchemaBuilder::new(&mut fbb).finish();
+ let block = crate::Block::new(offset, meta_length, body_length);
+ let blocks = fbb.create_vector(&[block]);
+
+ let mut footer = crate::FooterBuilder::new(&mut fbb);
+ footer.add_version(crate::MetadataVersion::V5);
+ footer.add_schema(schema);
+ footer.add_recordBatches(blocks);
+ let root = footer.finish();
+ fbb.finish(root, None);
+
+ let footer_data = fbb.finished_data();
+ let footer_len = footer_data.len() as i32;
+
+ let mut file = Vec::new();
+ file.extend_from_slice(&crate::ARROW_MAGIC);
+ file.extend_from_slice(&[0u8; 100]);
+ file.extend_from_slice(footer_data);
+ file.extend_from_slice(&footer_len.to_le_bytes());
+ file.extend_from_slice(&crate::ARROW_MAGIC);
+ file
+ }
+
+ /// A block's declared offset, metadata length, and body length are read
from the footer,
+ /// so they cannot be trusted. Declaring implausible lengths or offsets
that extend beyond
+ /// the file length must be rejected with an ArrowError before attempting
any buffer allocation.
+ #[test]
+ fn test_file_reader_rejects_implausible_block_length() {
+ for (body_length, meta_length, offset) in [
+ (i64::MAX, 10, 8),
+ (1 << 50, 10, 8),
+ (-1, 10, 8),
+ (10, -1, 8),
+ (10, 10, -1),
+ (1000, 100, 8),
+ (100, 100, i64::MAX - 50),
+ ] {
+ let file = file_with_declared_block(body_length, meta_length,
offset);
+ let mut reader = match
FileReaderBuilder::new().build(std::io::Cursor::new(file)) {
+ Ok(reader) => reader,
+ Err(err) => {
+ assert!(
+ matches!(err, ArrowError::ParseError(_)),
+ "expected ParseError for block ({body_length},
{meta_length}, {offset}): {err}"
+ );
+ continue;
Review Comment:
we shouldnt have this approach in tests; it makes it unclear which test case
here is expected to pass or fail this specific assertion. can we split the
cases up to be clear which should successfully build a reader and which should
fail
--
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]