Skip to content

Commit 9394a57

Browse files
committed
fix: use usize::try_from for footer_size casts to prevent silent truncation
Replace bare `footer_size as usize` casts with `usize::try_from(footer_size)` to prevent silent truncation on 32-bit platforms where a positive i64 value exceeding u32::MAX would wrap. Apply consistently across table.rs and table_changes.rs to match the pattern already used in table_deletions.rs.
1 parent 7b42b23 commit 9394a57

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/table.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,9 @@ impl DuckLakeTable {
300300
);
301301
if let Some(footer_size) = delete_file.footer_size
302302
&& footer_size > 0
303+
&& let Ok(hint) = usize::try_from(footer_size)
303304
{
304-
pf = pf.with_metadata_size_hint(footer_size as usize);
305+
pf = pf.with_metadata_size_hint(hint);
305306
}
306307

307308
// Create file scan config for the delete file
@@ -361,8 +362,9 @@ impl DuckLakeTable {
361362
// This reduces I/O from 2 reads to 1 read per file (especially beneficial for S3/MinIO)
362363
if let Some(footer_size) = table_file.file.footer_size
363364
&& footer_size > 0
365+
&& let Ok(hint) = usize::try_from(footer_size)
364366
{
365-
pf = pf.with_metadata_size_hint(footer_size as usize);
367+
pf = pf.with_metadata_size_hint(hint);
366368
}
367369

368370
Ok(pf)
@@ -441,8 +443,9 @@ impl DuckLakeTable {
441443
);
442444
if let Some(footer_size) = table_file.file.footer_size
443445
&& footer_size > 0
446+
&& let Ok(hint) = usize::try_from(footer_size)
444447
{
445-
pf = pf.with_metadata_size_hint(footer_size as usize);
448+
pf = pf.with_metadata_size_hint(hint);
446449
}
447450

448451
// Use read_schema (with original Parquet names) for reading

src/table_changes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,9 @@ impl TableChangesTable {
449449
);
450450
if let Some(footer_size) = data_file.footer_size
451451
&& footer_size > 0
452+
&& let Ok(hint) = usize::try_from(footer_size)
452453
{
453-
pf = pf.with_metadata_size_hint(footer_size as usize);
454+
pf = pf.with_metadata_size_hint(hint);
454455
}
455456

456457
// Determine what to read from Parquet

0 commit comments

Comments
 (0)