Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ All notable changes to this project are documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed
- `/commit/<oid>` no longer silently truncates a 64-hex component to its
40-char prefix on SHA-1 repositories. The component length is now
validated against the repository's object format per RFC 0000 §3.1
(a full oid is exactly 40 hex on SHA-1, 64 on SHA-256); a
wrong-length string returns ENOENT instead of resolving to whatever
commit its 40-char prefix names. Note: SHA-256 repositories remain
unmountable altogether — libgit2 rejects them at open time with
`unknown object format` — so on current builds the 64-hex form could
only ever manifest as this prefix alias.

## [0.0.4] - 2026-09-26

### Fixed
Expand Down
9 changes: 6 additions & 3 deletions src/gitmount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,12 @@ int Gitmount::resolve_locked(const std::string& path, Node* out) {
case Ns::Remote:
return resolve_remote_locked(p.comps, out);
case Ns::Commit: {
// Full lowercase oid only, pointing at a commit object itself —
// no peeling, replace refs never honored (RFC 0000 §3.1).
if (!pathmap::is_full_oid(p.comps[0])) return -ENOENT;
// Full lowercase oid only, matching the repository's object format
// (RFC 0000 §3.1): a 64-hex string on a SHA-1 repository is not a
// full oid — libgit2's git_oid_fromstr would silently parse only the
// first 40 chars (prefix alias).
const std::size_t hexsz = repo_->oid_type() == GIT_OID_SHA1 ? 40 : 64;
if (p.comps[0].size() != hexsz || !pathmap::is_full_oid(p.comps[0])) return -ENOENT;
git_oid oid{};
if (git_oid_fromstr(&oid, p.comps[0].c_str()) != 0) return -ENOENT;
if (!repo_->is_commit_object(oid)) return -ENOENT;
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ zz" "$(ls -1 "$MNT/tag/foo")"
check "/commit rejects uppercase oid" \
test ! -e "$MNT/commit/$(echo "$MAIN_TIP" | tr a-z A-Z)"
check "/commit rejects short prefix" test ! -e "$MNT/commit/${MAIN_TIP:0:8}"
# 64-hex is not a full oid on this SHA-1 fixture: before the length check
# git_oid_fromstr silently parsed the first 40 chars (prefix alias, #6).
OVERLONG_OID="${MAIN_TIP}000000000000000000000000" # 40 + 24 = 64 hex
check "/commit 40-hex commit dir lists (SHA-1 full oid)" \
ls "$MNT/commit/$MAIN_TIP/src"
check "/commit rejects 64-hex oid (SHA-1 prefix alias)" \
test ! -e "$MNT/commit/$OVERLONG_OID"
check "/commit rejects 64-hex deep path" \
test ! -e "$MNT/commit/$OVERLONG_OID/src/hello.txt"

# --- refs/replace not honored (§3.1) ---
check_eq "replace refs ignored (original R1 content)" "original R1" \
Expand Down
Loading