xanderbailey commented on code in PR #3773:
URL: https://github.com/apache/iceberg-rust/pull/3773#discussion_r4789360323
##########
crates/iceberg/src/puffin/reader.rs:
##########
@@ -70,7 +71,24 @@ impl PuffinReader {
validate_puffin_compression(blob_metadata.compression_codec)?;
let start = blob_metadata.offset;
- let end = start + blob_metadata.length;
+ let min_offset = u64::from(FileMetadata::MAGIC_LENGTH);
Review Comment:
Is the header-magic check needed? Java's `PuffinReader` doesn't have it:
`readAll` just seeks to `offset` and reads `length` bytes, so a blob at offset
0 returns the magic bytes. Reading bytes 0..4 can't panic or over-allocate, so
this check isn't about safety the way the other two are. It adds a rule that
the other implementations don't enforce, is this a short comming in the java
implementation?
##########
crates/iceberg/src/puffin/reader.rs:
##########
@@ -178,4 +196,72 @@ mod tests {
.contains("is not supported for Puffin files")
);
}
+
+ fn test_blob_metadata(offset: u64, length: u64) -> BlobMetadata {
+ BlobMetadata {
+ r#type: "test-type".to_string(),
+ fields: vec![1],
+ snapshot_id: 1,
+ sequence_number: 1,
+ offset,
+ length,
+ compression_codec: CompressionCodec::None,
+ properties: HashMap::new(),
+ }
+ }
+
+ #[tokio::test]
+ async fn test_blob_offset_length_overflow_returns_error() {
+ let reader = PuffinReader::new(java_uncompressed_metric_input_file())
+ .await
+ .unwrap();
+
+ for (offset, length) in [(u64::MAX, 1), (10, u64::MAX - 5)] {
+ let err = reader
+ .blob(&test_blob_metadata(offset, length))
+ .await
+ .unwrap_err();
+ assert_eq!(err.kind(), ErrorKind::DataInvalid);
+ assert!(
+ err.message().contains("overflows"),
Review Comment:
Could these assert the full message with `assert_eq!` rather than
`contains`? I think it makes it more precise.
##########
crates/iceberg/src/puffin/reader.rs:
##########
@@ -178,4 +196,72 @@ mod tests {
.contains("is not supported for Puffin files")
);
}
+
+ fn test_blob_metadata(offset: u64, length: u64) -> BlobMetadata {
+ BlobMetadata {
+ r#type: "test-type".to_string(),
+ fields: vec![1],
+ snapshot_id: 1,
+ sequence_number: 1,
+ offset,
+ length,
+ compression_codec: CompressionCodec::None,
+ properties: HashMap::new(),
+ }
+ }
+
+ #[tokio::test]
+ async fn test_blob_offset_length_overflow_returns_error() {
+ let reader = PuffinReader::new(java_uncompressed_metric_input_file())
+ .await
+ .unwrap();
+
+ for (offset, length) in [(u64::MAX, 1), (10, u64::MAX - 5)] {
+ let err = reader
+ .blob(&test_blob_metadata(offset, length))
+ .await
+ .unwrap_err();
+ assert_eq!(err.kind(), ErrorKind::DataInvalid);
+ assert!(
+ err.message().contains("overflows"),
+ "unexpected error: {err}"
+ );
+ }
+ }
+
+ #[tokio::test]
+ async fn test_blob_range_exceeding_file_length_returns_error() {
Review Comment:
Could you add a boundary test? A blob ending exactly at `file_length` should
pass, and one ending a byte later 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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]