Skip to content

Commit 97ed5a3

Browse files
committed
Merge fix-f-drive-parity: snapshot name_count before link-chaining
2 parents 2830729 + 2906aec commit 97ed5a3

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

crates/uffs-mft/src/io/parser/index_extension.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ pub(super) fn parse_extension_to_index(
505505
let record_idx = index.frs_to_idx[base_frs_usize];
506506
if record_idx != NO_ENTRY {
507507
let record = &mut index.records[record_idx as usize];
508+
// Snapshot name_count BEFORE link-chaining modifies it (for child entries)
509+
let pre_chain_name_count = record.name_count;
508510

509511
// Add new links to the record
510512
if !link_indices.is_empty() {
@@ -682,9 +684,8 @@ pub(super) fn parse_extension_to_index(
682684

683685
// Build parent-child relationship for names added from extension records
684686
// This is critical for compute_tree_metrics() to work correctly.
685-
// Get the current name_count to determine the name_index for each new name
686-
let record = &index.records[record_idx as usize];
687-
let existing_name_count = record.name_count;
687+
// Use the name_count from BEFORE link-chaining to avoid overflow
688+
let existing_name_count = pre_chain_name_count;
688689

689690
for (name_idx, (_, parent_frs)) in names.iter().enumerate() {
690691
let p_frs = *parent_frs;

crates/uffs-mft/src/parse/direct_index_extension.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,8 @@ pub(super) fn parse_extension_to_index(
600600
let record_idx = index.frs_to_idx[base_frs_usize];
601601
if record_idx != NO_ENTRY {
602602
let record = &mut index.records[record_idx as usize];
603+
// Snapshot name_count BEFORE link-chaining modifies it (for child entries)
604+
let pre_chain_name_count = record.name_count;
603605

604606
// Add new links to the record
605607
if !link_indices.is_empty() {
@@ -719,9 +721,8 @@ pub(super) fn parse_extension_to_index(
719721

720722
// Build parent-child relationship for names added from extension records
721723
// This is critical for compute_tree_metrics() to work correctly.
722-
// Get the current name_count to determine the name_index for each new name
723-
let record = &index.records[record_idx as usize];
724-
let existing_name_count = record.name_count;
724+
// Use the name_count from BEFORE link-chaining to avoid overflow
725+
let existing_name_count = pre_chain_name_count;
725726

726727
for (name_idx, (_, parent_frs)) in names.iter().enumerate() {
727728
let p_frs = *parent_frs;

0 commit comments

Comments
 (0)