Repository navigation
Description
[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).
Summary
In a gem library project made with bundle gem (the template of Bundler 2.6 and 4.1), scan --mode vendored followed by the commit it asks for makes the next gem build / rake build / rake release pack every vendored gem into the library's own .gem. The template's gemspec lists its files with git ls-files and rejects only a few prefixes (bin/, Gemfile, .gitignore, on 2.6 also test/, spec/, .git), so the committed .socket/vendor/ tree is part of spec.files. Neither the scan output nor the Ruby sections of docs/ecosystems.md say so, and gem build prints nothing about it.
Agent mode has the small form of the same thing: the committed .socket/manifest.json is packed into the gem.
Impact
- The released gem carries full copies of other gems: its runtime dependencies and also development-only tools such as rake. With a gem vendored from prebuilt platform gems (nokogiri), it carries the native binaries of every locked platform.
- Measured: a template library with
rackandnokogirias runtime dependencies andrakein the Gemfile builds a 5.6 KB gem with 5 files before the scan, and a 14.9 MB gem with 757 files (12.so/.bundlebinaries) after it. Installed, it takes 37 MB in every consumer's gem home. - The copies are not on the load path, so nothing breaks at build time and nobody notices until the gem is on rubygems.org, where a release cannot be replaced, only yanked. Consumers still resolve the upstream
rackandnokogiri(apath:in the library's Gemfile doesn't travel with the gem), so the shipped copies also patch nothing for them, and a scanner that reads the gem's contents now finds a second rack and nokogiri inside it. rollbackrestores the project (the tree equals the pre-scan commit), but not a gem that was already pushed.
Repro
Needs a patch service that serves a patch for rack 2.2.26 (I used the repo's stand-in, tests/nokogiri/patch_service.rb, for rack, rake and nokogiri 1.18.10).
bundle gem mylib --no-test --no-ci --no-mit --no-coc --no-changelog --no-linter --no-ext
cd mylib
# in mylib.gemspec: fill the TODO fields and add
# spec.add_dependency "rack", "~> 2.2.26"
# spec.add_dependency "nokogiri", "1.18.10"
# in Gemfile: gem "rake", "13.2.1"
echo "/vendor/bundle/" >> .gitignore
bundle config set --local path vendor/bundle && bundle install
git add -A && git commit -m init
gem build mylib.gemspec
tar -xOf mylib-0.1.0.gem data.tar.gz | tar -tz | wc -l # 5
ls -l mylib-0.1.0.gem # 5632 bytes
socket-patch scan --mode vendored # "Vendored 3 packages." exit 0
# Next steps:
# 1. Commit .socket/vendor/ and the updated lockfiles to make the patches portable.
git add -A && git commit -m "vendor patches"
gem build mylib.gemspec # no new warning
tar -xOf mylib-0.1.0.gem data.tar.gz | tar -tz | wc -l # 757
tar -xOf mylib-0.1.0.gem data.tar.gz | tar -tz | grep -c '^.socket/' # 752
ls -l mylib-0.1.0.gem # 14866432 bytesAmong the packed files:
.socket/vendor/state.json
.socket/vendor/gem/<uuid>/socket-patch.vendor.json
.socket/vendor/gem/<uuid>/rack-2.2.26/lib/rack.rb
.socket/vendor/gem/<uuid>/rake-13.2.1/... (a development-only gem)
.socket/vendor/gem/<uuid>/nokogiri-1.18.10/aarch64-linux-gnu/lib/nokogiri/3.3/nokogiri.so
gem install of that file elsewhere unpacks all of it under gems/mylib-0.1.0/.socket/.
With rack and rake only (Bundler 4.1.1): 5 files / 5.6 KB before, 148 files / 250 KB after. After scan --mode agent and its "Commit .socket/" step: 6 files, .socket/manifest.json among them.
Expected
Do no harm to the build: what the project ships should be what it shipped before the scan. docs/ecosystems.md covers gem library projects in vendored mode ("Ruby gems: gems vendored mode refuses" names a gem library's development dependency), and its vendored sections describe what is committed, but nothing says the committed tree ends up in the library's gem. One of:
- the vendored scan (and the agent scan) warns when a
*.gemspecbeside the Gemfile buildsspec.filesfromgit ls-files(orDir[...]patterns that would match.socket/), naming the fix: add.socket/to the gemspec's rejected prefixes; - the docs say the same in the Ruby vendored section;
--mode vendoredpoints library projects at hosted mode, which adds nothing to the tree.
Actual
The scan exits 0 with only the commit step, gem build gives no warning, and the gem grows from 5 to 757 files.
Versions
| socket-patch | Bundler | Ruby | Result |
|---|---|---|---|
main cfc870f |
4.1.1 (template rejects bin/ Gemfile .gitignore) |
3.3.6 | reproduces: 5 files → 148 (rack, rake) |
main cfc870f |
2.6.9 (template rejects bin/ test/ spec/ features/ .git appveyor Gemfile) |
3.3.6 | reproduces: 5 files → 757, 5.6 KB → 14.9 MB (rack, rake, nokogiri on 3 platforms) |
| 5.1.0 | 4.1.1 | 3.3.6 | reproduces: 5 files → 149 |
main cfc870f, --mode hosted |
4.1.1 | 3.3.6 | does not reproduce (nothing is added to the tree; the template leaves Gemfile out) |
Not a regression. Linux only; nothing here depends on the platform, so macOS and Windows should behave the same.
Suspect code
Nothing looks at the gemspec's file list. The places that could say it: the vendored next steps in crates/socket-patch-cli/src/commands/vendor.rs:4964, and the gem backend's commit-set handling in crates/socket-patch-core/src/vendor/gem.rs:1953 (where it already checks .gitignore rules for the vendored directory).
Generated by Claude Code
Activity