Skip to content

Fix crash on out-of-order GPT partitions and sanitize chunk boundaries - #143

Merged
Virv12 merged 1 commit into
masterfrom
disk-fixes
Sep 23, 2026
Merged

Virv12 merged 1 commit into
masterfrom
disk-fixes

Conversation

@veluca93

Copy link
Copy Markdown
Contributor

Sort GPT partitions by starting byte offset in Disk::partitions and parse_gpt, preventing an assertion failure in parse_disk when partition table entries are not listed in chronological LBA order.

Also sanitize and clamp partition chunk boundaries across all filesystems:

  • Use integer division for NTFS cluster count to avoid extending past partition boundaries on unaligned partitions.
  • Clamp ext4 blocks_count to partition size and limit block bitmap iteration to blocks_per_group.
  • Clamp FAT total_sectors to partition size and avoid underflow.
  • Clamp all partition chunks to [begin, end) in parse_gpt and parse_partition.
  • Skip zero-sized chunks in parse_disk.

Comment thread pixie-uefi/src/os/disk.rs Outdated
.collect::<Result<_, _>>()?;
.collect::<Result<Vec<_>, _>>()?;

x.sort_by_key(|p| p.byte_start);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are sorting this twice

return Ok(None);
}
};
partitions.sort_by_key(|p| p.byte_start);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are sorting this twice

- Sort GPT partitions by starting byte offset in parse_gpt so
  partitions listed out of order in the GPT array are processed in
  disk order, preventing an assertion crash in parse_disk.
- Use integer division for NTFS cluster count calculation so cluster
  ranges do not exceed partition boundaries when a partition's size is
  not an exact multiple of the cluster size.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Flash codec micro-benchmark (chunk_codec)'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: e19e2de Previous: 84cbe4b Ratio
chunk_codec::benches::bench_flash_roundtrip_200kib 341526.65 ns/iter (± 3188.19) 140351.3 ns/iter (± 1637.14) 2.43

This comment was automatically generated by workflow using github-action-benchmark.

@Virv12
Virv12 merged commit 0f53076 into master Sep 23, 2026
1 of 2 checks passed
@Virv12
Virv12 deleted the disk-fixes branch September 23, 2026 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants