Skip to content

Commit

Permalink
Fix cargo registry index paths for big-endian architectures (#574)
Browse files Browse the repository at this point in the history
The hexadecimal part of cargo index paths is different on little- and
big-endian architectures.
See also EmbarkStudios/tame-index#36

I have verified that the endianness-specific `CRATES_IO_SPARSE_DIR`
definition is correct and indeed matches what cargo writes to on
big-endian architectures.
  • Loading branch information
decathorpe authored Nov 7, 2023
1 parent 6a26873 commit 2f5300f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/advisories/helpers/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,26 +742,50 @@ mod test {

{
let url = Url::parse("https://github.com/RustSec/advisory-db").unwrap();

#[cfg(target_endian = "little")]
assert_eq!(
url_to_db_path(root_path.clone(), &url).unwrap(),
root_path.join("github.com-a946fc29ac602819")
);

#[cfg(target_endian = "big")]
assert_eq!(
url_to_db_path(root_path.clone(), &url).unwrap(),
root_path.join("github.com-f4edf1c00e90fd42")
);
}

{
let url = Url::parse("https://bare.com").unwrap();

#[cfg(target_endian = "little")]
assert_eq!(
url_to_db_path(root_path.clone(), &url).unwrap(),
root_path.join("bare.com-9c003d1ed306b28c")
);

#[cfg(target_endian = "big")]
assert_eq!(
url_to_db_path(root_path.clone(), &url).unwrap(),
root_path.join("bare.com-c9767e4ee31501de")
);
}

{
let url = Url::parse("https://example.com/countries/việt nam").unwrap();

#[cfg(target_endian = "little")]
assert_eq!(
url_to_db_path(root_path.clone(), &url).unwrap(),
root_path.join("example.com-1c03f84825fb7438")
);

#[cfg(target_endian = "big")]
assert_eq!(
url_to_db_path(root_path.clone(), &url).unwrap(),
root_path.join("example.com-5ebf17a6f3e576f0")
);
}
}
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ pub enum Source {

/// The directory name under which crates sourced from the crates.io sparse
/// registry are placed
#[cfg(target_endian = "little")]
const CRATES_IO_SPARSE_DIR: &str = "index.crates.io-6f17d22bba15001f";
#[cfg(target_endian = "big")]
const CRATES_IO_SPARSE_DIR: &str = "index.crates.io-d11c229612889eed";

impl Source {
pub fn crates_io(is_sparse: bool) -> Self {
Expand Down

0 comments on commit 2f5300f

Please sign in to comment.