This is an automated email from the ASF dual-hosted git repository.
JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git
The following commit(s) were added to refs/heads/main by this push:
new cb8633dc fix(blob): accept legacy Python CRCs (#1467)
cb8633dc is described below
commit cb8633dc01f02ceff711a5b413879975c49468e0
Author: XiaoHongbo <[email protected]>
AuthorDate: Sun Nov 22 20:31:49 2026 +0800
fix(blob): accept legacy Python CRCs (#1467)
---
crates/paimon/src/arrow/format/blob.rs | 324 ++++++++++++++++++---
crates/paimon/src/arrow/format/mod.rs | 5 +-
crates/paimon/src/spec/core_options.rs | 29 ++
crates/paimon/src/table/data_evolution_reader.rs | 141 +++++++++
.../table/data_evolution_reader/blob_fallback.rs | 45 ++-
docs/src/python-binding.md | 21 ++
6 files changed, 529 insertions(+), 36 deletions(-)
diff --git a/crates/paimon/src/arrow/format/blob.rs
b/crates/paimon/src/arrow/format/blob.rs
index 608938db..5928d13e 100644
--- a/crates/paimon/src/arrow/format/blob.rs
+++ b/crates/paimon/src/arrow/format/blob.rs
@@ -49,6 +49,7 @@ pub(crate) struct BlobFormatReader {
descriptor_mode: bool,
file_path: String,
blob_parallelism: usize,
+ verify_crc: bool,
}
impl BlobFormatReader {
@@ -57,9 +58,15 @@ impl BlobFormatReader {
descriptor_mode,
file_path,
blob_parallelism: DEFAULT_BLOB_READ_PARALLELISM,
+ verify_crc: true,
}
}
+ pub(crate) fn with_crc_verification(mut self, verify_crc: bool) -> Self {
+ self.verify_crc = verify_crc;
+ self
+ }
+
pub(crate) fn with_blob_parallelism(mut self, blob_parallelism: usize) ->
Self {
debug_assert!(blob_parallelism > 0);
self.blob_parallelism = blob_parallelism;
@@ -73,6 +80,7 @@ pub(crate) struct IndexedBlobReader {
descriptor_mode: bool,
file_path: String,
blob_parallelism: usize,
+ verify_crc: bool,
}
impl IndexedBlobReader {
@@ -108,9 +116,15 @@ impl IndexedBlobReader {
descriptor_mode,
file_path,
blob_parallelism,
+ verify_crc: true,
})
}
+ pub(crate) fn with_crc_verification(mut self, verify_crc: bool) -> Self {
+ self.verify_crc = verify_crc;
+ self
+ }
+
pub(crate) fn num_rows(&self) -> usize {
self.index.num_rows()
}
@@ -123,7 +137,13 @@ impl IndexedBlobReader {
build_descriptor_values(&self.index, positions, &self.file_path)
} else {
let planned_reads = plan_blob_reads(&self.index, positions)?;
- fetch_blob_values(self.reader.as_ref(), planned_reads,
self.blob_parallelism).await
+ fetch_blob_values(
+ self.reader.as_ref(),
+ planned_reads,
+ self.blob_parallelism,
+ self.verify_crc,
+ )
+ .await
}
}
@@ -138,6 +158,7 @@ impl IndexedBlobReader {
&self.file_path,
self.descriptor_mode,
self.blob_parallelism,
+ self.verify_crc,
)
.await
}
@@ -155,6 +176,7 @@ impl IndexedBlobReader {
self.descriptor_mode,
key_type,
self.blob_parallelism,
+ self.verify_crc,
)
.await
}
@@ -232,7 +254,8 @@ impl FormatFileReader for BlobFormatReader {
self.descriptor_mode,
self.blob_parallelism,
)
- .await?;
+ .await?
+ .with_crc_verification(self.verify_crc);
let mut selection = RowSelectionCursor::new(blob_reader.num_rows(),
row_selection)?;
Ok(try_stream! {
@@ -694,6 +717,7 @@ async fn fetch_blob_values(
reader: &dyn FileRead,
planned_reads: Vec<PlannedBlobRead>,
blob_parallelism: usize,
+ verify_crc: bool,
) -> crate::Result<Vec<BlobReadValue>> {
let mut values = Vec::with_capacity(planned_reads.len());
let mut entry_reads = Vec::new();
@@ -712,7 +736,7 @@ async fn fetch_blob_values(
}
for resolved in read_merged_blob_entries(reader, entry_reads,
blob_parallelism).await? {
- let value = decode_blob_entry(resolved.entry, resolved.range)?;
+ let value = decode_blob_entry(resolved.entry, resolved.range,
verify_crc)?;
values[resolved.result_index] = Some(BlobReadValue::Value(value));
}
collect_blob_read_values(values)
@@ -859,12 +883,20 @@ fn blob_entry_range(payload_range: &Range<u64>) ->
Range<u64> {
payload_range.start - BLOB_INLINE_HEADER_SIZE..payload_range.end +
BLOB_TRAILER_SIZE
}
-async fn read_blob_entry(reader: &dyn FileRead, entry_range: Range<u64>) ->
crate::Result<Bytes> {
+async fn read_blob_entry(
+ reader: &dyn FileRead,
+ entry_range: Range<u64>,
+ verify_crc: bool,
+) -> crate::Result<Bytes> {
let entry = reader.read(entry_range.clone()).await?;
- decode_blob_entry(entry, entry_range)
+ decode_blob_entry(entry, entry_range, verify_crc)
}
-fn decode_blob_entry(entry: Bytes, entry_range: Range<u64>) ->
crate::Result<Bytes> {
+fn decode_blob_entry(
+ entry: Bytes,
+ entry_range: Range<u64>,
+ verify_crc: bool,
+) -> crate::Result<Bytes> {
let expected_entry_length = entry_range.end - entry_range.start;
if entry.len() as u64 != expected_entry_length {
return Err(Error::DataInvalid {
@@ -904,16 +936,25 @@ fn decode_blob_entry(entry: Bytes, entry_range:
Range<u64>) -> crate::Result<Byt
});
}
- let expected_crc =
u32::from_le_bytes(entry[crc_offset..].try_into().unwrap());
- let actual_crc = crc32fast::hash(&entry[..crc_offset]);
- if actual_crc != expected_crc {
- return Err(Error::DataInvalid {
- message: format!(
- "Blob entry CRC32 mismatch at offset {}: expected
{expected_crc:#010x}, got {actual_crc:#010x}",
- entry_range.start
- ),
- source: None,
- });
+ if verify_crc {
+ let expected_crc =
u32::from_le_bytes(entry[crc_offset..].try_into().unwrap());
+ // Python writers before apache/paimon#9426 omitted the trailing length
+ // from the checksum. Share the payload scan between both checksums;
+ // the embedded length is still checked independently above.
+ let mut hasher = crc32fast::Hasher::new();
+ hasher.update(&entry[..length_offset]);
+ let legacy_crc = hasher.clone().finalize();
+ hasher.update(&entry[length_offset..crc_offset]);
+ let actual_crc = hasher.finalize();
+ if actual_crc != expected_crc && legacy_crc != expected_crc {
+ return Err(Error::DataInvalid {
+ message: format!(
+ "Blob entry CRC32 mismatch at offset {}: expected
{expected_crc:#010x}, got {actual_crc:#010x}",
+ entry_range.start
+ ),
+ source: None,
+ });
+ }
}
Ok(entry.slice(BLOB_INLINE_HEADER_SIZE as usize..length_offset))
@@ -987,6 +1028,7 @@ async fn fetch_blob_array_values(
file_path: &str,
descriptor_mode: bool,
blob_parallelism: usize,
+ verify_crc: bool,
) -> crate::Result<Vec<BlobReadValue>> {
if !descriptor_mode {
return fetch_inline_nested_blob_values(
@@ -994,6 +1036,7 @@ async fn fetch_blob_array_values(
planned_reads,
blob_parallelism,
InlineNestedBlobKind::Array,
+ verify_crc,
)
.await;
}
@@ -1206,10 +1249,11 @@ async fn read_blob_array_range(
async fn read_inline_blob_array_entry(
reader: &dyn FileRead,
payload_range: Range<u64>,
+ verify_crc: bool,
) -> crate::Result<BlobReadValue> {
let _preflight_layout = read_blob_array_layout(reader,
payload_range.clone()).await?;
- let payload = read_blob_entry(reader,
blob_entry_range(&payload_range)).await?;
+ let payload = read_blob_entry(reader, blob_entry_range(&payload_range),
verify_crc).await?;
let payload_length = validate_blob_array_payload_range(&payload_range)?;
if payload.len() as u64 != payload_length {
return Err(Error::DataInvalid {
@@ -1296,6 +1340,7 @@ async fn fetch_blob_map_values(
descriptor_mode: bool,
key_type: &DataType,
blob_parallelism: usize,
+ verify_crc: bool,
) -> crate::Result<Vec<BlobReadValue>> {
if !descriptor_mode {
return fetch_inline_nested_blob_values(
@@ -1306,6 +1351,7 @@ async fn fetch_blob_map_values(
file_path,
key_type,
},
+ verify_crc,
)
.await;
}
@@ -1315,8 +1361,15 @@ async fn fetch_blob_map_values(
PlannedBlobArrayRead::Null => Ok(BlobReadValue::Null),
PlannedBlobArrayRead::Placeholder =>
Ok(BlobReadValue::Placeholder),
PlannedBlobArrayRead::Read(payload_range) => {
- read_blob_map_entry(reader, payload_range, file_path,
descriptor_mode, key_type)
- .await
+ read_blob_map_entry(
+ reader,
+ payload_range,
+ file_path,
+ descriptor_mode,
+ key_type,
+ verify_crc,
+ )
+ .await
}
}
}))
@@ -1339,6 +1392,7 @@ async fn fetch_inline_nested_blob_values(
planned_reads: Vec<PlannedBlobArrayRead>,
blob_parallelism: usize,
kind: InlineNestedBlobKind<'_>,
+ verify_crc: bool,
) -> crate::Result<Vec<BlobReadValue>> {
let mut values = Vec::with_capacity(planned_reads.len());
let mut entry_reads = Vec::new();
@@ -1366,14 +1420,21 @@ async fn fetch_inline_nested_blob_values(
};
let value = match kind {
InlineNestedBlobKind::Array => {
- read_inline_blob_array_entry(&memory_reader,
payload_range).await?
+ read_inline_blob_array_entry(&memory_reader, payload_range,
verify_crc).await?
}
InlineNestedBlobKind::Map {
file_path,
key_type,
} => {
- read_blob_map_entry(&memory_reader, payload_range, file_path,
false, key_type)
- .await?
+ read_blob_map_entry(
+ &memory_reader,
+ payload_range,
+ file_path,
+ false,
+ key_type,
+ verify_crc,
+ )
+ .await?
}
};
values[result_index] = Some(value);
@@ -1387,6 +1448,7 @@ async fn read_blob_map_entry(
file_path: &str,
descriptor_mode: bool,
key_type: &DataType,
+ verify_crc: bool,
) -> crate::Result<BlobReadValue> {
let payload_length = payload_range
.end
@@ -1603,7 +1665,7 @@ async fn read_blob_map_entry(
})
.collect::<crate::Result<Vec<_>>>()?
} else {
- let payload = read_blob_entry(reader,
blob_entry_range(&payload_range)).await?;
+ let payload = read_blob_entry(reader,
blob_entry_range(&payload_range), verify_crc).await?;
reads
.into_iter()
.map(|range| {
@@ -3335,7 +3397,7 @@ mod tests {
let reader = TrackingFileRead::new(Bytes::from(payload.clone()));
let key_type =
DataType::VarChar(VarCharType::new(VarCharType::MAX_LENGTH).unwrap());
- read_blob_map_entry(&reader, 0..payload.len() as u64, "", true,
&key_type)
+ read_blob_map_entry(&reader, 0..payload.len() as u64, "", true,
&key_type, true)
.await
.unwrap();
@@ -3407,9 +3469,10 @@ mod tests {
let (reader, payload_range) = sparse_blob_map_entry(&[0],
&[value_length as i64]);
let key_type =
DataType::VarChar(VarCharType::new(VarCharType::MAX_LENGTH).unwrap());
- let _error = read_blob_map_entry(&reader, payload_range.clone(), "",
false, &key_type)
- .await
- .unwrap_err();
+ let _error =
+ read_blob_map_entry(&reader, payload_range.clone(), "", false,
&key_type, true)
+ .await
+ .unwrap_err();
assert!(
reader.ranges().contains(&blob_entry_range(&payload_range)),
@@ -3423,7 +3486,7 @@ mod tests {
let (reader, payload_range) = sparse_blob_map_entry(&[key_length as
i64], &[0]);
let key_type =
DataType::VarChar(VarCharType::new(VarCharType::MAX_LENGTH).unwrap());
- let error = read_blob_map_entry(&reader, payload_range.clone(), "",
false, &key_type)
+ let error = read_blob_map_entry(&reader, payload_range.clone(), "",
false, &key_type, true)
.await
.unwrap_err();
@@ -3438,7 +3501,7 @@ mod tests {
let (reader, payload_range) = sparse_blob_map_entry(&[key_length as
i64], &[0]);
let key_type = DataType::Int(crate::spec::IntType::new());
- let error = read_blob_map_entry(&reader, payload_range.clone(), "",
false, &key_type)
+ let error = read_blob_map_entry(&reader, payload_range.clone(), "",
false, &key_type, true)
.await
.unwrap_err();
@@ -3452,7 +3515,7 @@ mod tests {
let (reader, payload_range) = sparse_blob_map_entry(&[-1], &[0]);
let key_type =
DataType::VarChar(VarCharType::new(VarCharType::MAX_LENGTH).unwrap());
- let error = read_blob_map_entry(&reader, payload_range, "", false,
&key_type)
+ let error = read_blob_map_entry(&reader, payload_range, "", false,
&key_type, true)
.await
.unwrap_err();
@@ -3516,7 +3579,7 @@ mod tests {
),
]);
- let _error = read_inline_blob_array_entry(&reader,
payload_range.clone())
+ let _error = read_inline_blob_array_entry(&reader,
payload_range.clone(), true)
.await
.unwrap_err();
@@ -3662,7 +3725,9 @@ mod tests {
}
let reader = TrackingFileRead::new(Bytes::from(bytes));
- let values = fetch_blob_values(&reader, planned_reads,
2).await.unwrap();
+ let values = fetch_blob_values(&reader, planned_reads, 2, true)
+ .await
+ .unwrap();
let actual = values
.into_iter()
.map(|value| match value {
@@ -3784,7 +3849,9 @@ mod tests {
.map(PlannedBlobRead::Entry)
.collect();
- let values = fetch_blob_values(&reader, planned_reads,
1).await.unwrap();
+ let values = fetch_blob_values(&reader, planned_reads, 1, true)
+ .await
+ .unwrap();
assert_eq!(values.len(), 3);
assert!(values.into_iter().all(|value| matches!(
@@ -3849,6 +3916,7 @@ mod tests {
PlannedBlobRead::Entry(second_start..second_end),
],
1,
+ true,
)
.await
.unwrap();
@@ -4227,6 +4295,196 @@ mod tests {
);
}
+ #[tokio::test]
+ async fn test_blob_crc_option_preserves_structure_checks() {
+ use crate::arrow::format::{
+ create_format_reader_with_budget, FormatReadFields,
MosaicPrefetchOptions,
+ };
+ let payload = b"hello";
+ let original =
blob_test_utils::build_blob_file_bytes(&[Some(payload.as_slice())]);
+ let fields = vec![DataField::new(
+ 0,
+ "payload".to_string(),
+ DataType::Blob(BlobType::new()),
+ )];
+ for verify in [true, false] {
+ let options = std::collections::HashMap::from([(
+ "blob.read.verify-crc".to_string(),
+ verify.to_string(),
+ )]);
+ let configured = create_format_reader_with_budget(
+ "data.blob",
+ false,
+ FormatReadFields {
+ data_schema: &fields,
+ projected: &fields,
+ },
+ &options,
+ None,
+ DEFAULT_BLOB_READ_PARALLELISM,
+ MosaicPrefetchOptions::default(),
+ )
+ .unwrap();
+ for (offset, message) in [
+ (0, "magic"),
+ (BLOB_INLINE_HEADER_SIZE as usize, "CRC32 mismatch"),
+ (
+ BLOB_INLINE_HEADER_SIZE as usize + payload.len(),
+ "length mismatch",
+ ),
+ ] {
+ let mut bytes = original.clone();
+ bytes[offset] ^= 0xff;
+ let result = async {
+ configured
+ .reader
+ .read_batch_stream(
+
Box::new(BytesFileRead(Bytes::from(bytes.clone()))),
+ bytes.len() as u64,
+ &fields,
+ None,
+ None,
+ None,
+ )
+ .await?
+ .try_collect::<Vec<_>>()
+ .await
+ }
+ .await;
+ if !verify && message == "CRC32 mismatch" {
+ let mut expected = payload.to_vec();
+ expected[0] ^= 0xff;
+ assert_eq!(
+ collect_binary_values(&result.unwrap()[0]),
+ vec![Some(expected)]
+ );
+ } else {
+ assert_data_invalid(result.unwrap_err(), message);
+ }
+ }
+ }
+ }
+
+ #[tokio::test]
+ async fn test_blob_reader_reads_legacy_python_fixtures() {
+ // Written by BlobFormatWriter at apache/paimon 19a933b7d9^ (before
#9426):
+ // add_blob("payload", BlobData(b"legacy"));
+ // add_blob_array("payload", [BlobData(b"legacy"), None,
BlobData(b"")]);
+ // add_blob_map("payload", {"key": BlobData(b"legacy")},
AtomicType("STRING"));
+ let fixtures = [
+ ("cf114e586c656761637916000000000000002ab4a15b2c0100000001",
vec![DataField::new(0, "payload".to_string(),
DataType::Blob(BlobType::new()))]),
+
("cf114e584243424101030000006c65676163790c0d0203000000260000000000000081ec551d4c0100000001",
blob_array_read_fields()),
+
("cf114e584243424d01010000006b65796c6567616379060c01000000010000002c00000000000000495fc62d580100000001",
blob_map_read_fields()),
+ ];
+ for (i, (hex, fields)) in fixtures.into_iter().enumerate() {
+ let file_bytes = (0..hex.len())
+ .step_by(2)
+ .map(|offset| u8::from_str_radix(&hex[offset..offset + 2],
16).unwrap())
+ .collect::<Vec<_>>();
+ let batches = BlobFormatReader::new(String::new(), false)
+ .read_batch_stream(
+ Box::new(BytesFileRead(Bytes::from(file_bytes.clone()))),
+ file_bytes.len() as u64,
+ &fields,
+ None,
+ None,
+ None,
+ )
+ .await
+ .unwrap()
+ .try_collect::<Vec<_>>()
+ .await
+ .unwrap();
+ // A bad checksum is accepted only with verification explicitly
disabled,
+ // including ARRAY and MAP materialization paths.
+ let mut corrupt = file_bytes.clone();
+ corrupt[[18, 34, 40][i]] ^= 0xff;
+ for verify_crc in [true, false] {
+ let result = async {
+ BlobFormatReader::new(String::new(), false)
+ .with_crc_verification(verify_crc)
+ .read_batch_stream(
+
Box::new(BytesFileRead(Bytes::from(corrupt.clone()))),
+ corrupt.len() as u64,
+ &fields,
+ None,
+ None,
+ None,
+ )
+ .await?
+ .try_collect::<Vec<_>>()
+ .await
+ }
+ .await;
+ if verify_crc {
+ assert_data_invalid(result.unwrap_err(), "CRC32 mismatch");
+ } else {
+ assert_eq!(result.unwrap(), batches);
+ }
+ }
+ match i {
+ 0 => assert_eq!(
+ collect_binary_values(&batches[0]),
+ vec![Some(b"legacy".to_vec())]
+ ),
+ 1 => assert_eq!(
+ collect_blob_array_values(&batches[0]),
+ vec![Some(vec![Some(b"legacy".to_vec()), None,
Some(vec![])])]
+ ),
+ 2 => assert_eq!(
+ collect_blob_map_values(&batches[0]),
+ vec![Some(vec![("key".to_string(),
Some(b"legacy".to_vec()))])]
+ ),
+ _ => unreachable!(),
+ }
+ }
+ }
+
+ #[tokio::test]
+ async fn test_blob_reader_accepts_legacy_python_crc() {
+ let payloads = [
+ Some(b"legacy".as_slice()),
+ Some(b"".as_slice()),
+ None,
+ Some(b"standard".as_slice()),
+ ];
+ let mut file_bytes = blob_test_utils::build_blob_file_bytes(&payloads);
+ // Historical Python CRC covered magic + payload, excluding the length.
+ let mut offset = 0;
+ for payload in payloads[..2].iter().flatten() {
+ let length_offset = offset + BLOB_INLINE_HEADER_SIZE as usize +
payload.len();
+ let crc_offset = length_offset + size_of::<i64>();
+ let crc = crc32fast::hash(&file_bytes[offset..length_offset]);
+ file_bytes[crc_offset..crc_offset + size_of::<u32>()]
+ .copy_from_slice(&crc.to_le_bytes());
+ offset = crc_offset + size_of::<u32>();
+ }
+ assert_eq!(
+ read_scalar_blob_values(file_bytes.clone()).await.unwrap(),
+ payloads
+ .iter()
+ .map(|v| v.map(|b| b.to_vec()))
+ .collect::<Vec<_>>()
+ );
+
+ for (offset, message) in [
+ (0, "magic"),
+ (BLOB_INLINE_HEADER_SIZE as usize, "CRC32 mismatch"),
+ (
+ BLOB_INLINE_HEADER_SIZE as usize + b"legacy".len(),
+ "length mismatch",
+ ),
+ (
+ BLOB_INLINE_HEADER_SIZE as usize + b"legacy".len() +
size_of::<i64>(),
+ "CRC32 mismatch",
+ ),
+ ] {
+ let mut corrupt = file_bytes.clone();
+ corrupt[offset] ^= 0xff;
+
assert_data_invalid(read_scalar_blob_values(corrupt).await.unwrap_err(),
message);
+ }
+ }
+
#[tokio::test]
async fn test_blob_reader_rejects_invalid_entry_magic() {
let payload = b"hello";
diff --git a/crates/paimon/src/arrow/format/mod.rs
b/crates/paimon/src/arrow/format/mod.rs
index 1edc5463..2d1fbe2e 100644
--- a/crates/paimon/src/arrow/format/mod.rs
+++ b/crates/paimon/src/arrow/format/mod.rs
@@ -40,7 +40,7 @@ use super::ReadBudget;
use super::RowFilterFactory;
use crate::io::{FileIO, FileRead, OutputFile};
use crate::spec::stats::BinaryTableStats;
-use crate::spec::{DataField, Predicate};
+use crate::spec::{CoreOptions, DataField, Predicate};
use crate::table::{ArrowRecordBatchStream, RowRange};
use crate::Error;
use arrow_array::RecordBatch;
@@ -448,7 +448,8 @@ pub(crate) fn create_format_reader_with_budget(
} else if lower.ends_with(".blob") {
Box::new(
blob::BlobFormatReader::new(path.to_string(), blob_as_descriptor)
- .with_blob_parallelism(blob_parallelism),
+ .with_blob_parallelism(blob_parallelism)
+
.with_crc_verification(CoreOptions::new(table_options).blob_read_verify_crc()?),
)
} else if lower.ends_with(".video") {
Box::new(video::VideoFormatReader::new(path.to_string()))
diff --git a/crates/paimon/src/spec/core_options.rs
b/crates/paimon/src/spec/core_options.rs
index 94835b6b..c43e38be 100644
--- a/crates/paimon/src/spec/core_options.rs
+++ b/crates/paimon/src/spec/core_options.rs
@@ -189,6 +189,7 @@ const DEFAULT_GLOBAL_INDEX_FALLBACK_SCAN_MAX_SIZE: i64 =
256 * 1024 * 1024;
const DEFAULT_BTREE_INDEX_CACHE_SIZE: i64 = 128 * 1024 * 1024;
const DEFAULT_BTREE_INDEX_HIGH_PRIORITY_POOL_RATIO: f64 = 0.1;
const BLOB_AS_DESCRIPTOR_OPTION: &str = "blob-as-descriptor";
+const BLOB_READ_VERIFY_CRC_OPTION: &str = "blob.read.verify-crc";
pub(crate) const BLOB_FIELD_OPTION: &str = "blob-field";
pub(crate) const BLOB_DESCRIPTOR_FIELD_OPTION: &str = "blob-descriptor-field";
pub(crate) const BLOB_DESCRIPTOR_FIELD_FALLBACK: &str =
"blob.stored-descriptor-fields";
@@ -2141,6 +2142,20 @@ impl<'a> CoreOptions<'a> {
.unwrap_or(false)
}
+ /// Verify BLOB entry CRCs when reading payloads. Enabled by default.
+ pub fn blob_read_verify_crc(&self) -> crate::Result<bool> {
+ match self.options.get(BLOB_READ_VERIFY_CRC_OPTION) {
+ None => Ok(true),
+ Some(value) if value.eq_ignore_ascii_case("true") => Ok(true),
+ Some(value) if value.eq_ignore_ascii_case("false") => Ok(false),
+ Some(value) => Err(crate::Error::ConfigInvalid {
+ message: format!(
+ "{BLOB_READ_VERIFY_CRC_OPTION} must be true or false, got
'{value}'"
+ ),
+ }),
+ }
+ }
+
/// Comma-separated BLOB field names stored in dedicated `.blob` files.
///
/// Fields listed in `blob-descriptor-field` or `blob-view-field` are also
@@ -4060,6 +4075,20 @@ mod tests {
}
}
+ #[test]
+ fn blob_read_verify_crc_defaults_on_and_rejects_invalid_values() {
+ let mut options = HashMap::new();
+ assert!(CoreOptions::new(&options).blob_read_verify_crc().unwrap());
+ for value in ["true", "TRUE"] {
+ options.insert(BLOB_READ_VERIFY_CRC_OPTION.into(), value.into());
+
assert!(CoreOptions::new(&options).blob_read_verify_crc().unwrap());
+ }
+ options.insert(BLOB_READ_VERIFY_CRC_OPTION.into(), "false".into());
+ assert!(!CoreOptions::new(&options).blob_read_verify_crc().unwrap());
+ options.insert(BLOB_READ_VERIFY_CRC_OPTION.into(), "typo".into());
+ assert!(CoreOptions::new(&options).blob_read_verify_crc().is_err());
+ }
+
#[test]
fn test_validate_scan_options_rejects_unsupported() {
for key in ["incremental-between", "incremental-between-scan-mode"] {
diff --git a/crates/paimon/src/table/data_evolution_reader.rs
b/crates/paimon/src/table/data_evolution_reader.rs
index 39dc38fe..6d203887 100644
--- a/crates/paimon/src/table/data_evolution_reader.rs
+++ b/crates/paimon/src/table/data_evolution_reader.rs
@@ -180,6 +180,7 @@ pub(super) fn read_blob_compaction(
file_io,
true,
DEFAULT_BLOB_READ_PARALLELISM,
+ true,
None,
)
}
@@ -1971,6 +1972,7 @@ fn open_source_stream(
file_io,
blob_as_descriptor,
blob_parallelism,
+ CoreOptions::new(&table_options).blob_read_verify_crc()?,
anchor_deletion_vector.cloned(),
);
}
@@ -1987,6 +1989,7 @@ fn open_source_stream(
file_io,
blob_as_descriptor,
blob_parallelism,
+ CoreOptions::new(&table_options).blob_read_verify_crc()?,
anchor_deletion_vector.cloned(),
);
}
@@ -5445,6 +5448,144 @@ mod tests {
assert_eq!(descriptor_rows[3], Some(Vec::new()));
}
+ #[tokio::test]
+ async fn test_nested_blob_fallback_obeys_crc_verification_option() {
+ use crate::spec::{MapType, VarCharType};
+ use arrow_array::{MapArray, StringArray};
+
+ // Historical Python writer fixtures. Corrupt only the outer BLOB
entry CRC;
+ // the ARRAY/MAP payload and row index remain structurally valid.
+ let cases = [
+ (
+ "array",
+
"cf114e584243424101030000006c65676163790c0d0203000000260000000000000081ec551d4c0100000001",
+ 34,
+
DataType::Array(ArrayType::new(DataType::Blob(BlobType::new()))),
+ ),
+ (
+ "map",
+
"cf114e584243424d01010000006b65796c6567616379060c01000000010000002c00000000000000495fc62d580100000001",
+ 40,
+ DataType::Map(MapType::new(
+ DataType::VarChar(VarCharType::string_type()),
+ DataType::Blob(BlobType::new()),
+ )),
+ ),
+ ];
+
+ for (kind, fixture, crc_offset, blob_type) in cases {
+ let tempdir = tempdir().unwrap();
+ let bucket_dir = tempdir.path().join("bucket-0");
+ fs::create_dir_all(&bucket_dir).unwrap();
+ let parquet_path = bucket_dir.join("data.parquet");
+ write_int_parquet_file(&parquet_path, vec![("id", vec![7])], None);
+
+ let base_path = bucket_dir.join("base.blob");
+ let mut bytes = hex::decode(fixture).unwrap();
+ bytes[crc_offset] ^= 0xff;
+ fs::write(&base_path, &bytes).unwrap();
+ let latest_path = bucket_dir.join("latest.blob");
+ write_blob_file_with_values(&latest_path,
&[BlobFixtureValue::Placeholder]);
+
+ let table_schema = TableSchema::new(
+ 0,
+ &Schema::builder()
+ .column("id", DataType::Int(IntType::new()))
+ .column("payloads", blob_type)
+ .option("data-evolution.enabled", "true")
+ .option("row-tracking.enabled", "true")
+ .build()
+ .unwrap(),
+ );
+ let table = Table::new(
+ FileIOBuilder::new("file").build().unwrap(),
+ Identifier::new("default",
format!("blob_{kind}_crc_fallback")),
+ local_file_path(tempdir.path()),
+ table_schema,
+ None,
+ );
+ let split = DataSplitBuilder::new()
+ .with_snapshot(1)
+ .with_partition(BinaryRow::new(0))
+ .with_bucket(0)
+ .with_bucket_path(local_file_path(&bucket_dir))
+ .with_total_buckets(1)
+ .with_data_files(vec![
+ data_file_meta_with_path(
+ "data.parquet",
+ 0,
+ 1,
+ 1,
+ parquet_path.metadata().unwrap().len() as i64,
+ Some(vec!["id"]),
+ ),
+ data_file_meta_with_path(
+ "base.blob",
+ 0,
+ 1,
+ 1,
+ base_path.metadata().unwrap().len() as i64,
+ Some(vec!["payloads"]),
+ ),
+ data_file_meta_with_path(
+ "latest.blob",
+ 0,
+ 1,
+ 2,
+ latest_path.metadata().unwrap().len() as i64,
+ Some(vec!["payloads"]),
+ ),
+ ])
+ .build()
+ .unwrap();
+
+ let default_read = TableRead::new(&table,
table.schema().fields().to_vec(), Vec::new());
+ let error = default_read
+ .to_arrow(std::slice::from_ref(&split))
+ .unwrap()
+ .try_collect::<Vec<_>>()
+ .await
+ .unwrap_err();
+ assert!(
+ error.to_string().contains("CRC32 mismatch"),
+ "{kind}: expected CRC failure, got {error}"
+ );
+
+ let unchecked = table.copy_with_options(HashMap::from([(
+ "blob.read.verify-crc".to_string(),
+ "false".to_string(),
+ )]));
+ let read = TableRead::new(&unchecked,
unchecked.schema().fields().to_vec(), Vec::new());
+ let batches = read
+ .to_arrow(std::slice::from_ref(&split))
+ .unwrap()
+ .try_collect::<Vec<_>>()
+ .await
+ .unwrap();
+ assert_eq!(collect_int_values(&batches, "id"), vec![7]);
+ let payload = batches[0].column_by_name("payloads").unwrap();
+ match kind {
+ "array" => assert_eq!(
+ collect_blob_array_values(&batches, "payloads"),
+ vec![Some(vec![Some(b"legacy".to_vec()), None,
Some(Vec::new())])]
+ ),
+ "map" => {
+ let map =
payload.as_any().downcast_ref::<MapArray>().unwrap();
+ let keys =
map.keys().as_any().downcast_ref::<StringArray>().unwrap();
+ let values = map
+ .values()
+ .as_any()
+ .downcast_ref::<LargeBinaryArray>()
+ .unwrap();
+ assert_eq!(map.value_length(0), 1);
+ assert_eq!(keys.value(0), "key");
+ assert_eq!(values.value(0), b"legacy");
+ }
+ _ => unreachable!(),
+ }
+ }
+ }
+
#[tokio::test]
async fn test_table_read_falls_back_across_blob_sequence_groups() {
use BlobFixtureValue::{Null, Placeholder, Value};
diff --git a/crates/paimon/src/table/data_evolution_reader/blob_fallback.rs
b/crates/paimon/src/table/data_evolution_reader/blob_fallback.rs
index 226f033b..03ea0cb6 100644
--- a/crates/paimon/src/table/data_evolution_reader/blob_fallback.rs
+++ b/crates/paimon/src/table/data_evolution_reader/blob_fallback.rs
@@ -68,6 +68,7 @@ impl LazyBlobFile {
file_io: &FileIO,
blob_as_descriptor: bool,
blob_parallelism: usize,
+ verify_crc: bool,
field_kind: &BlobFieldKind,
) -> crate::Result<Vec<BlobReadValue>> {
if self.reader.is_none() {
@@ -99,7 +100,8 @@ impl LazyBlobFile {
blob_as_descriptor,
blob_parallelism,
)
- .await?,
+ .await?
+ .with_crc_verification(verify_crc),
)
};
let indexed_rows =
@@ -154,6 +156,7 @@ pub(super) fn read(
file_io: FileIO,
blob_as_descriptor: bool,
blob_parallelism: usize,
+ verify_crc: bool,
anchor_deletion_vector: Option<DeletionVectorContext>,
) -> crate::Result<ArrowRecordBatchStream> {
if read_fields.len() != 1 ||
!read_fields[0].data_type().is_blob_file_field() {
@@ -221,6 +224,7 @@ pub(super) fn read(
&file_io,
blob_as_descriptor,
blob_parallelism,
+ verify_crc,
&field_kind,
).await?;
}
@@ -248,6 +252,7 @@ fn coalesce_disjoint_groups(groups: &mut
Vec<VecDeque<LazyBlobFile>>) {
groups.push(files.into());
}
+#[allow(clippy::too_many_arguments)]
async fn resolve_batch(
sequence_groups: &mut [VecDeque<LazyBlobFile>],
row_ids: &[i64],
@@ -255,6 +260,7 @@ async fn resolve_batch(
file_io: &FileIO,
blob_as_descriptor: bool,
blob_parallelism: usize,
+ verify_crc: bool,
field_kind: &BlobFieldKind,
) -> crate::Result<RecordBatch> {
let mut resolved = (0..row_ids.len())
@@ -308,6 +314,7 @@ async fn resolve_batch(
file_io,
blob_as_descriptor,
blob_parallelism,
+ verify_crc,
field_kind,
)
.await?;
@@ -486,6 +493,7 @@ mod tests {
&file_io,
false,
1,
+ true,
&BlobFieldKind::Scalar,
)
.await
@@ -523,6 +531,7 @@ mod tests {
&file_io,
false,
1,
+ true,
&BlobFieldKind::Scalar,
)
.await
@@ -539,6 +548,39 @@ mod tests {
}
}
+ #[tokio::test]
+ async fn test_lazy_blob_file_crc_configuration() {
+ let dir = tempfile::tempdir().unwrap();
+ let path = dir.path().join("data.blob");
+ let mut bytes =
blob_test_utils::build_blob_file_bytes(&[Some(b"hello".as_slice())]);
+ bytes[4] ^= 0xff;
+ std::fs::write(&path, &bytes).unwrap();
+ let file_io = crate::io::FileIOBuilder::new("file").build().unwrap();
+ for verify_crc in [true, false] {
+ let mut file = LazyBlobFile {
+ range: RowRange::new(0, 0),
+ file_name: "data.blob".to_string(),
+ path: path.to_str().unwrap().to_string(),
+ file_size: bytes.len() as i64,
+ row_count: 1,
+ reader: None,
+ };
+ let result = file
+ .read_positions(&[0], &file_io, false, 1, verify_crc,
&BlobFieldKind::Scalar)
+ .await;
+ if verify_crc {
+ assert!(
+ matches!(result, Err(Error::DataInvalid { message, .. })
if message.contains("CRC32 mismatch"))
+ );
+ } else {
+ let values = result.unwrap();
+ assert!(
+ matches!(&values[0], BlobReadValue::Value(value) if
value.as_ref() == &bytes[4..9])
+ );
+ }
+ }
+ }
+
#[tokio::test]
async fn test_resolve_batch_skips_payloads_for_resolved_rows() {
use BlobFixtureValue::{Null, Placeholder, Value};
@@ -589,6 +631,7 @@ mod tests {
&file_io,
false,
crate::arrow::format::blob::DEFAULT_BLOB_READ_PARALLELISM,
+ true,
&BlobFieldKind::Scalar,
)
.await
diff --git a/docs/src/python-binding.md b/docs/src/python-binding.md
index 8a469568..83fee3c2 100644
--- a/docs/src/python-binding.md
+++ b/docs/src/python-binding.md
@@ -371,6 +371,27 @@ schema recorded in that snapshot. An update to a dropped
field is rejected even
if its name is reused or DDL has not published a new data snapshot. This check
includes fields nested inside written ROW, ARRAY, MAP, and MULTISET columns.
+## BLOB CRC verification
+
+Rust verifies CRC32 when materializing managed `.blob` entries. It accepts both
+standard checksums and historical Python checksums written before
+[apache/paimon#9426](https://github.com/apache/paimon/pull/9426), which
excluded
+the trailing length. Both checksums share one payload scan.
+
+The read option `blob.read.verify-crc` defaults to `true`. To skip CRC
calculation:
+
+```python
+rb = table.new_read_builder({"blob.read.verify-crc": "false"})
+# Continue with scan-then-read using this builder.
+```
+
+This option applies to scalar, array, and map BLOB materialization, including
+Data Evolution reads. Magic, entry length, and range checks remain enabled;
+payload corruption detectable only by CRC is no longer rejected when disabled.
+Writers continue producing standard checksums. Descriptor-only reads do not
+materialize the full entry and do not verify its CRC; this option does not add
+verification to external objects or Python-side descriptor fetching.
+
## Column Projection
Use `with_projection` to select specific columns. Only the requested columns
are read, reducing I/O.