skillshare icon indicating copy to clipboard operation
skillshare copied to clipboard

ComputeFileHashes aborts and discards all hashes on a single unreadable file (e.g. directory symlink)

Open cescox opened this issue 3 months ago β€’ 1 comments

Bug

internal/install/meta.go's ComputeFileHashes walks a skill directory with filepath.Walk and hashes every entry. If hashing a single file fails, the error propagates out of the walk and the function returns (nil, err) β€” discarding every hash already computed, not just the one that failed.

Concretely, a directory symlink triggers this: filepath.Walk uses Lstat-based IsDir(), so a symlink pointing at a directory isn't recognized as a directory and falls through to the hashing branch. utils.FileHashFormatted calls os.Open, which does follow the symlink, opens the target directory, and io.Copy fails with "is a directory."

Repro

Track any repo containing a directory symlink, e.g. garrytan/gstack, which has connect-chrome -> open-gstack-browser:

skillshare install https://github.com/garrytan/gstack.git --track
skillshare doctor
# β†’ "1 skill(s) missing file hashes: _gstack"

544 skills in that package, zero get hashed, because of one symlink.

Impact

FileHashes backs doctor's tamper-detection (cmd/skillshare/doctor.go, comparing stored vs. recomputed hashes) β€” the integrity mechanism the security-first philosophy docs describe. Losing hash coverage for a whole package over one unreadable path is disproportionate and, at scale, means large tracked repos silently lose tamper detection entirely.

Proposed fix (edited β€” see note below)

Scoped down after reading the current codebase, particularly the fix that just landed for #271. Two parts, both inside ComputeFileHashes, no signature change:

  1. In the filepath.Walk callback, classify directory symlinks explicitly (info.Mode()&os.ModeSymlink != 0, target is a dir) and skip hashing them rather than trying to read through them β€” matches how git itself tracks symlinks (as link text, not dereferenced content).
  2. On any per-file hash failure (this case or otherwise β€” permission-denied, broken symlink, etc.), don't abort the walk: call ui.Warning(...) and continue. internal/install already does exactly this for a comparable non-fatal problem (install_config.go:253, ui.Warning("post-install hook failed for %s: %v", ...)), so this stays consistent with the package's existing conventions rather than introducing a new one.

No new metadata field or schema change needed: every caller of ComputeFileHashes already does if hashes, hashErr := ComputeFileHashes(x); hashErr == nil { meta.FileHashes = hashes }, so once the function stops erroring on a single bad file, _gstack goes from 0/544 hashed to 543/544 automatically, with zero other call sites touched. Visibility is also already covered without persisting anything: doctor's verify phase recomputes hashes live on every run (cmd/skillshare/doctor.go:863), so the ui.Warning reprints every doctor run for as long as the file stays unhashable β€” no risk of it being a one-time, easy-to-miss message.

Happy to open a PR with this + a test fixture (a skill dir containing a directory symlink, and one with a permission-denied file) if the approach looks right to you.


Edit: originally proposed a larger version of this fix (new HashGaps metadata field, schema addition, touching several call sites) without having looked at the current code first. After reading the new install_apply.go and the #271 fix that just landed, replaced it with the smaller version above, which reuses patterns already in this codebase instead of adding new ones. Sorry for the churn β€” should have read the updated source before writing the first version.

cescox avatar Sep 02 '26 08:09 cescox

Thanks for the detailed report! I’ve committed a focused fix in ea442b9f: directory symlinks are skipped during hashing, while file symlinks continue to hash their target contents.

Other hash failures still return errors, since returning partial hashes could let doctor incorrectly report β€œverified.” Added regression tests for directory symlinks, file symlinks, and broken links. All checks pass.

The fix will be included in the next release.

runkids avatar Sep 05 '26 03:09 runkids