Repository navigation
Fix vendored mode failing for a gem patch that names the gem's own gemspec - #2485
Mikola Lysenko (mikolalysenko) wants to merge 2 commits into
Conversation
A patch that fixes a gem's file permissions names every file the gem
ships. Many gems ship `<name>.gemspec` at their root, the path where a
vendored copy carries the stub gemspec bundler evaluates for a path
source. Vendored mode wrote the stub and then compared that path with
the hash the patch records, so `scan --mode vendored` failed with
`vendor_prebuilt_required` ("extracted to an unexpected layout") for
octopoller 0.2.0 (GHSA-26qj-cr27-r5c4), and left nothing vendored.
- The downloaded gem is now held to every file of the patch before the
stub is written, for a gem's own tree and for each platform gem's
tree. A served gem whose own gemspec is not the recorded one is still
refused.
- The vendored copy is no longer held to the patch's hash at the stub's
path: in the in-sync test of a re-run, and in `vendor --check`, `vex`
and `repair`. The stub's bytes stay covered by the ledger's inventory.
Without that exemption every later run would rebuild the copy and
`vex` would not attest it.
- A copy whose patch names nothing but that gemspec, and whose ledger
entry has no inventory, is not attested.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review follow-ups for the vendored gem fix: - A re-run over a copy whose patch names nothing but the gem's own `<name>.gemspec` had no file left to hash and called any existing copy in sync. It now holds such a copy to the ledger's inventory and rebuilds it when a file changed or the ledger has none. - Only a plain gem name names a stub path, so a ledger entry whose name holds a `/` cannot exempt a file below the root. - The run's result lists the files the copy is held to, without the gemspec the stub replaced. - Reworded three comments that said a gem never ships a `<name>.gemspec`, or that every file of the patch is hashed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview Adds New Reviewed by Cursor Bugbot for commit 218db94. Configure here. |
scan --mode vendoredfails for a gem patch that names the gem's own<name>.gemspec. This fixes it, so the patch for octopoller 0.2.0 (GHSA-26qj-cr27-r5c4) can be vendored.Why
socket-patch scan --mode vendoredon a project that locks octopoller 0.2.0 exits 1 withvendor_prebuilt_required: "prebuilt .gem for octopoller extracted to an unexpected layout (patched files absent at their recorded paths)". Nothing is vendored. Agent mode and hosted mode apply the same patch correctly.octopoller.gemspecat its root, as most gems built from bundler's template do. A vendored copy carries the stub gemspec at exactly that path, because bundler evaluates<name>.gemspecof a path source. Vendored mode wrote the stub first and then compared that path with the hash the patch records.<name>.gemspechit the same check.What changes
vendor --check,vexandrepair. Without it the first vendor would pass, every later run would rebuild the copy, andvexwould not attest it. The match is exact:<name>.gemspecat the root of the tree, nothing deeper.vendor --checkandvexcompare the whole tree with, and a re-run still requires a valid stub.vendor --checkandvexdo not attest it without an inventory (no_files), and a re-run holds it to the inventory and rebuilds it when a file changed or there is none.Other ecosystems are untouched: the exemption is applied only to gem entries.
How it was checked
scan --mode vendoredunderumask 000, on a project whose installed copy had 22 group- and world-writable files: 22 files vendored, none group- or world-writable (0644/0755), andoctopoller.gemspecin the copy is the stub.scanreportsalready_vendored, with no warning and no rebuild.bundle installsucceeds andrequire "octopoller"loads from the vendored copy.vendor --checkverifies the artifact and wiring.vexwrites one statement:not_affectedfor GHSA-26qj-cr27-r5c4.vendor --checkexits 1 withvendor_hash_mismatch,repairrestores it and the check passes again. After the copy is deleted,scanrestores it.rollbackrestores the Gemfile and the lock.vendor::gem):cargo test -p socket-patch-core --lib: 9,027 passed.cargo clippy --locked --workspace --all-features -- -D warningsandcargo fmt --checkare clean.Review
/code-review highon this branch found no fault in the two download checks and five edge cases. Four are fixed in the second commit: the re-run over a copy whose patch names only the gemspec, a ledger name with a/in it, the result's file list, and three stale comments. The fifth is the case-insensitive filesystem gap below. I left it because the copy of such a gem already differs between filesystems today (one file on macOS and Windows, two on Linux), and making the trees agree changes what existing vendored copies are restored to. Before this change such a gem could not be vendored at all when its patch names the gemspec, so this is not a regression.Known gaps, not changed here
.gitignorethe patch names. The vendored copy empties a.gitignorethe gem ships when its rules would hide a file of the copy, unless the patch names that.gitignore. A permissions patch names it, so for a gem whose.gitignorehides one of its own shipped files the copy is refused as gitignored. Octopoller is not affected.rollbackwording. For this patch,rollbackprints both "1 gem still holds the patched build on disk" and "Replaced the installed copy of 1 gem with the upstream build". The patched and upstream files have the same content, so the first message is misleading. It predates this change.redcloth.gemspecforRedCloth), on macOS or Windows the stub overwrites that file, so a patch that names it vendors once and then failsvendor --checkand is rebuilt on every run.🤖 Generated with Claude Code