Repository navigation
Conversation
…d_blobs In `crates/core/src/commands/prune.rs`, `find_used_blobs` unconditionally called `.unwrap()` on `node.subtree` when iterating over `NodeType::Dir` nodes. If a repository contains a corrupted or malformed snapshot / tree where a directory entry has `subtree: None`, running `prune` caused an unhandled panic (`called Option::unwrap() on a None value`). Safely check `node.subtree` with `if let Some(subtree)` when collecting used blobs, ignoring missing directory subtrees rather than crashing. Also add unit regression tests verifying that directory nodes with and without subtree IDs are handled gracefully. Reported-by: BS.ehlas.cz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem & Root Cause
In
crates/core/src/commands/prune.rs,find_used_blobsiterates over tree nodes and unconditionally calls.unwrap()onnode.subtreewhen encountering nodes of typeNodeType::Dir:If a repository contains a corrupted or malformed snapshot / tree where a directory entry has
subtree: None, runningprunecauses an unhandled panic:This crashes the host application and prevents users from pruning or cleaning up the repository.
Solution
collect_used_node_blobsand safely checknode.subtreeusingif let Some(subtree) = node.subtree.subtreeisNone, the missing subtree is safely skipped rather than panicking.crates/core/src/commands/prune.rsverifying that directory nodes without a subtree do not panic and that directory nodes with a subtree are correctly recorded.Disclaimer: Found the issue by test-driving an LM-powered vulnerability scanner I work on heavily.