Checksum mismatch for registries served with `Content-Encoding: gzip` (e.g. GitHub Pages)

オープン
#3,991 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
rust
領域
build-system

調査の方向性

まず、リンクされた自己完結型リポジトリで cargo run と bazel run :main を実行して失敗を再現し、次に Accept-Encoding: gzip の有無でチェックサムを比較します。rules_rust crate のダウンロード経路を追跡し、修正箇所が downloader なのかリクエストヘッダーなのかを判断します; Cargo.lock のチェックサムで registry crate がダウンロードされ、再現ケースが正常にビルドできれば完了です。

索引モデルが issue の本文から書いたものです。

説明

awaiting-response crate-universe

We use a custom registry at Proton and found that we get a checksum mismatch when crate_universe fetches .crate files from it. The registry is hosted on GitHub Pages, which applies Content-Encoding: gzip based on the client's Accept-Encoding header.

I was able to reproduce this in a self-contained repository, please see https://github.com/mgeisler/gh-pages-registry-demo.

Environment

Bazel 9.1.0
rules_rust 0.70.0
OS macOS 26 (arm64)

Repository structure

Path Purpose
greet/ Library crate published to the registry
hello/ Binary crate that depends on greet via the registry

The registry is live at https://mgeisler.github.io/gh-pages-registry-demo/.

Reproducing the bug

Building with Cargo works:

cd hello && cargo run

Building with Bazel fails (Cargo.lock is already committed, no repinning needed):

cd hello && bazel run :main

Bazel output:

WARNING: Download from https://mgeisler.github.io/gh-pages-registry-demo/crates/greet-0.1.0.crate failed:
  class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException
  Checksum was   dd22f693a0dc4bcd8d59c30b12ffe47ee355586964f211ba0878892ba46dfd3a
             but wanted 93afd84f9dc5cd2b9dacc42f1dec536595ed068214a844c4e0a8a7032a7397f0
ERROR: An error occurred during the fetch of repository 'rules_rust++crate+crates__greet-0.1.0':
  Error in download_and_extract: java.io.IOException: Error downloading
  [https://mgeisler.github.io/gh-pages-registry-demo/crates/greet-0.1.0.crate]:
  Checksum was   dd22f693a0dc4bcd8d59c30b12ffe47ee355586964f211ba0878892ba46dfd3a
             but wanted 93afd84f9dc5cd2b9dacc42f1dec536595ed068214a844c4e0a8a7032a7397f0
ERROR: Build did NOT complete successfully

Verifying the root cause with Curl

Without Accept-Encoding — what Cargo does; digest matches Cargo.lock:

curl -L "https://mgeisler.github.io/gh-pages-registry-demo/crates/greet-0.1.0.crate" \
  | sha256sum
# → 93afd84f9dc5cd2b9dacc42f1dec536595ed068214a844c4e0a8a7032a7397f0  ✓

With Accept-Encoding: gzip — what Bazel's HTTP client sends:

curl -L -H "Accept-Encoding: gzip" \
  "https://mgeisler.github.io/gh-pages-registry-demo/crates/greet-0.1.0.crate" \
  | sha256sum
# → dd22f693a0dc4bcd8d59c30b12ffe47ee355586964f211ba0878892ba46dfd3a  ✗

The response headers confirm that Fastly re-compresses the already-gzipped .crate:

content-type:     application/octet-stream
content-encoding: gzip
vary:             Accept-Encoding

We can verify this by hand:

curl -L -H "Accept-Encoding: gzip" \
    "https://mgeisler.github.io/gh-pages-registry-demo/crates/greet-0.1.0.crate" \
    | gunzip | sha256sum
# → 93afd84f9dc5cd2b9dacc42f1dec536595ed068214a844c4e0a8a7032a7397f0  ✓

Bazel hashes the gzip-encoded wire bytes: the .crate (already a .tar.gz) is gzipped a second time by Fastly, and Bazel checksums that doubly-compressed payload without decompressing it first.

Root cause

Bazel's downloader does not strip Content-Encoding: gzip before computing the SHA-256 checksum, contrary to how every other HTTP client behaves. The issue affects any Cargo registry whose CDN honours Accept-Encoding: gzip on binary responses — GitHub Pages (fronted by Fastly) is a reliable example.

Possible fixes

Suggested by my AI, I would of course love to hear other ideas:

  1. Bazel-side (preferred): compute SHA-256 after decompressing Content-Encoding: gzip, consistent with other HTTP client libraries.
  2. rules_rust: do not emit Accept-Encoding: gzip when issuing crate download requests (e.g. via a --header downloader flag).
  3. rules_rust: expose a per-URL or per-registry option to suppress specific request headers in the generated http_archive calls.
主要言語
Starlark
スター
857
フォーク
701
平均マージ
4日 7時間
マージ済み PR(30日)
46

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

bazelbuild/rules_rust のほかの issue

bazelbuild/rules_rust の issue をすべて見る

似ている issue

Build System の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。