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

Ouverte
#145 5 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
65/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
r
Domaine
cli, tooling

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
R
Étoiles
30
Forks
19
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de r-lib/pkgcache

Toutes les issues de r-lib/pkgcache

Issues similaires

Plus d'issues R

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.