Repository navigation
Fix base64 checksums in a gem compact index (#2285) - #2288
Mikola Lysenko (mikolalysenko) wants to merge 5 commits into
Conversation
Refs #2285 Assisted-by: Claude Code:claude-fable-5-2
A static index built with `gem generate_index` writes the sha256 of a gem as base64. Bundler reads it and pins the hex digest. The unit test and the hosted unwind test fail until the reader does the same. Refs #2285 Assisted-by: Claude Code:claude-fable-5-2
A static index built with `gem generate_index` writes the sha256 of a gem as base64 where rubygems.org writes hex. Bundler converts it and pins the hex digest in CHECKSUMS. The reader took only hex, so behind such a server SOCKET_RUBYGEMS_URL could not restore a hosted pin, and the agent-mode source gem download found no checksum. Read the digest as Bundler's Checksum.to_hexdigest does: 64 hex digits, or 43 base64 digits of either alphabet and one `=`. Anything else is still no checksum. Fixes #2285 Assisted-by: Claude Code:claude-fable-5-2
The agent-mode build picks a missing gem's release from the compact index with a second reader, which also takes only a hex digest. The hosted unwind test drops its URL-safe leg: the fixture gem's digest has no `+` or `/`, so that leg served the same index. The unit tests cover the alphabet. Refs #2285 Assisted-by: Claude Code:claude-fable-5-2
pick_release, the reader the agent-mode build uses for a gem the home lacks, took only a hex `checksum:`, so behind a `gem generate_index` server every release was skipped. It reads the digest as compact_index_checksum does now. Refs #2285 Assisted-by: Claude Code:claude-fable-5-2
|
bugbot run Generated by Claude Code |
PR SummaryMedium Risk Overview A new Unit tests cover standard and URL-safe base64, malformed digests, and Reviewed by Cursor Bugbot for commit 8284fa9. Configure here. |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 8284fa9. Configure here.
|
[agent] Generated by Claude Code |
|
[agent] PR shepherd: review brief for the approver What it does Risk: low. It only widens what's accepted as a digest. Hex input takes the same path as before. Malformed base64 (missing or doubled padding, trailing bits set, wrong length) still counts as "no checksum". The digest is still checked against the downloaded bytes, so a wrong decode can't let an unverified gem through. No lock, manifest or output format changes. Look here
Verified
Changes I made: none. Open questions: none. The description notes that uppercase hex is lowercased where Bundler keeps its case. That isn't new, and no known server writes uppercase hex. Generated by Claude Code |
LLM Description written by Claude Code:claude-fable-5-2
Fixes #2285
Summary
A gem server built with
gem generate_indexwrites the sha256 in its compact index (info/<name>) as base64. rubygems.org writes hex. Bundler reads both and pins the hex digest inCHECKSUMS. socket-patch read only hex, so behind such a server:rollback/removeof a hosted gem pin refused with "lists no ruby-platform 3.2.9 with a checksum", althoughSOCKET_RUBYGEMS_URLnamed the server and the index listed one;Both readers now take the digest the way Bundler's
Checksum.to_hexdigestdoes: 64 hex digits, or 43 base64 digits (standard or URL-safe alphabet) and one=, converted to lowercase hex. Anything Bundler refuses as a digest is still "no checksum", so the refusal stays for an index that really has none. No lock, manifest or output format changes.Root cause
Two functions parse a compact-index line, and both passed the
checksum:value throughsha256_hex, which accepts only 64 hex digits:compact_index_checksum(patch/redirect/upstream/client.rs), used by the hosted unwind and by the source-gem download;pick_release(patch/gem_source.rs), used when the native build needs a gem the home lacks.The fix is one helper,
utils::digest::sha256_hex_or_base64, called by both.Evidence
compact_index_checksum_reads_a_base64_digest_as_bundler_does(core, the linegem generate_indexwrote for rack 3.2.9, both alphabets, six malformed digests)hosted_unwind_restores_a_mirror_gem_whose_index_checksum_is_base64(e2e_redirect_gem_stale_install: scan, thenrollbackandremovewithSOCKET_RUBYGEMS_URLon a base64 index; pair byte for byte, upstream gem back)pick_release_takes_the_newest_release_that_fits(base64 case added)a_compact_index_digest_is_read_as_hex_or_base64(the new helper)The red commits come before the fix commits in the history. The accepted base64 shape was checked against Bundler 4.0.18's
checksum.rband Ruby 3.3.6's strict decoder (unpack1("m0")): no padding,==, or bits set past the 32nd byte are refused there and here.Run locally:
cargo clippy --locked --workspace --all-features -- -D warnings(the CI command): clean. With--all-targetsthere are lint errors in test code that are onmaintoo; none is in a file this PR touches.cargo test -p socket-patch-coreandcargo test -p socket-patch-cli --lib --bins: pass.cargo test -p socket-patch-cli --test e2e_redirect_gem_stale_install: 68 passed.e2e_gem_native_ext_build: 43 passed, 11 ignored.Docs: the
SOCKET_RUBYGEMS_URLrow ofCLI_CONTRACT.mdand "Ruby gems: gems already installed" indocs/ecosystems.mdnow say both encodings are read.Review
/code-review highfound three things:pick_releasewas a second hex-only reader. Fixed, with a test.+or/). The leg is removed; the unit tests cover the alphabet.Follow-ups
gem generate_indexserver or a real native build behind one: the tests use the index line that command wrote, served by a stand-in.hosted-e2eandci-okare expected to be red because of CI: hosted-e2e gem leg fails on every PR: production published activestorage 6.0.3 patch 146ef6aa, not in GEM_UUIDS #2270, which fails onmaintoo.https://claude.ai/code/session_011f9aePYSz8M6vqhE3wfJ3t
Generated by Claude Code