SHA256 from `PACKAGES` is not checked against the downloaded file

オープン
#145 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
65/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
r
領域
cli, tooling

調査の方向性

Look at package-cache.R lines 275-282 where sha256 is replaced, and packages-gz.R lines 466-470 where the race happens. The fix involves adding a hash check after download_one_of() returns, before accepting the file. Also ensure the SHA256sum: field is parsed correctly, stripping whitespace and newlines. Test by simulating a mismatch with a mock download source.

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

説明

The sha256 that pkgdepends passes to async_copy_or_add() is never compared with the download. After download_one_of() returns, it is replaced by the hash of whatever arrived:

https://github.com/r-lib/pkgcache/blob/cd17b44b751802a756c87a52abdccb82806119b7/R/package-cache.R#L275-L282

For CRAN macOS binaries, download_one_of() races the CRAN mirror against mac.cran.dev and keeps the first to finish, so a stale file on mac.cran.dev gets installed even if it does not match PACKAGES:

https://github.com/r-lib/pkgcache/blob/cd17b44b751802a756c87a52abdccb82806119b7/R/packages-gz.R#L466-L470

This is currently the case for adbcdrivermanager 0.24.0-3 on macOS with R 4.6. Since the zstd mix-up (r-lib/pkgdepends#485, r-lib/pak#915), the file on cran.rstudio.com is gzip again and matches PACKAGES (3b73522a…), while mac.cran.dev still serves the zstd file (2bd7d854…). Our CI got the mac.cran.dev copy and failed with "unknown archive type".

A check would also need the hash parsed correctly. The SHA256sum: field in CRAN's macOS PACKAGES is folded onto a continuation line. Base R's read.dcf() returns the bare hash, but the parsed value here keeps the line break and indentation:

pak::pkg_download(
  "adbcdrivermanager",
  dest_dir = tempfile(),
  platforms = "aarch64-apple-darwin23",
  r_versions = "4.6",
  dependencies = FALSE
)$sha256
#> [1] "\n        3b73522a5d65d7dad8ddcbfed2045da6d61ae25458d3c973f55928d937166ed5"

Could a download that does not match the expected hash be rejected, so the other source is used instead? If that sounds reasonable, I'm happy to propose a PR.

主要言語
R
スター
30
フォーク
19
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

r-lib/pkgcache のほかの issue

r-lib/pkgcache の issue をすべて見る

似ている issue

R の issue をもっと見る

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

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