Skip to content

Commit b6a67d7

Browse files
committed
doc: make clear that indices can contain invalid or dangerous paths.
It's probably best not to try to protect against violations of constraints in this free-to-mutate data-structure and instead suggest to validate entry paths before using them on disk (or use the `gix_worktree::Stack`).
1 parent 886d6b5 commit b6a67d7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

gix-index/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ pub struct AccelerateLookup<'a> {
113113
///
114114
/// As opposed to a snapshot, it's meant to be altered and eventually be written back to disk or converted into a tree.
115115
/// We treat index and its state synonymous.
116+
///
117+
/// # A note on safety
118+
///
119+
/// An index (i.e. [`State`]) created [from a tree](State::from_tree()) is not guaranteed to have valid entry paths as those
120+
/// depend on the names contained in trees entirely, without applying any level of validation.
121+
///
122+
/// This means that before using these paths to recreate files on disk, *they must be validated*.
123+
///
124+
/// It's notable that it's possible to manufacture tree objects which contain names like `.git/hooks/pre-commit`
125+
/// which then will look like `.git/hooiks/pre-commit` in the index, which doesn't care that the name came from a single
126+
/// tree instead of from trees named `.git`, `hooks` and a blob named `pre-commit`. The effect is still the same - an invalid
127+
/// path is presented in the index and its consumer must validate each path component before usage.
128+
///
129+
/// It's recommended to do that using `gix_worktree::Stack` which has it built-in if it's created `for_checkout()`. Alternatively
130+
/// one can validate component names with `gix_validate::path::component()`.
116131
#[derive(Clone)]
117132
pub struct State {
118133
/// The kind of object hash used when storing the underlying file.

0 commit comments

Comments
 (0)