Exemple
getrandom 0.3.4: getrandom 0.3 unsupported backend compiles cleanly but fails non-empty fills with Error::UNSUPPORTED while short-circuiting empty slices to Ok
Échantillon vérifié pour cargo getrandom 0.3.4: getrandom 0.3 unsupported backend compiles cleanly but fails non-empty fills with Error::UNSUPPORTED while…
sha256:846965d520a96d1f4fc9e250730d0cd97cc28ba1781205f81eee92cf0b08ee85
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 3
- Clés de signature qui l’ont compilé
- 3
Environnement déclaré
rust linux x64 rust rust cargo
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| rust 1 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1 |
2026-08-16 |
| rust 1 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1 |
2026-08-18 |
| rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b… |
2026-09-08 |
Cas
HOW- Objectif
- getrandom 0.3 unsupported backend compiles cleanly but fails non-empty fills with Error::UNSUPPORTED while short-circuiting empty slices to Ok
- Paquets
- Symboles
-
- getrandom::fill
- getrandom::fill_uninit
- getrandom::u32
- getrandom::u64
- getrandom::Error::UNSUPPORTED
- getrandom::Error::raw_os_error
- getrandom::Error::new_custom
- Environnement
- rust
- Créé
- 2026-08-16T09:17:06Z
Contrat
- assert getrandom compiles cleanly with --cfg getrandom_backend="unsupported"
- assert getrandom::fill fails non-empty buffers with Error::UNSUPPORTED
- assert getrandom::u32 and u64 fail with Error::UNSUPPORTED
- assert getrandom::fill on empty buffer succeeds with Ok
- assert getrandom::fill_uninit on empty buffer succeeds with Ok
- assert Error::UNSUPPORTED returns None for raw_os_error
Fichiers
- .cargo/config.toml
- .gitignore
- Cargo.lock
- Cargo.toml
- NOTES.md
- csx.json
- src/lib.rs
Code source
[build]
rustflags = ["--cfg", "getrandom_backend=\"unsupported\""]
/target
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "getrandom"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasip2",
]
[[package]]
name = "libc"
version = "0.2.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
[[package]]
name = "r-efi"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "sample-getrandom"
version = "0.1.0"
dependencies = [
"getrandom",
]
[[package]]
name = "wasip2"
version = "1.0.4+wasi-0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487"
dependencies = [
"wit-bindgen",
]
[[package]]
name = "wit-bindgen"
version = "0.57.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"
[package]
name = "sample-getrandom"
version = "0.1.0"
edition = "2021"
[dependencies]
getrandom = "0.3.4"
`search_known_solution` answered with existing sample `sha256:c2eb1cbf62ff348c61fce622c4530f916dcacb95669348c5545ad7c5a4153384` covering custom backend symbol linking `__getrandom_v03_custom`.
A model would expect missing/unsupported platform entropy to fail loudly at compile time (like in getrandom 0.2), expect empty buffer fills to fail alongside non-empty fills, or expect `Error::raw_os_error()` and `.code()` / `CUSTOM_START` to expose integer codes.
Fails silently with a green build at compile time when `--cfg getrandom_backend="unsupported"` is set, then at runtime non-empty entropy calls return `Err(Error::UNSUPPORTED)` (with `raw_os_error() == None`) while empty buffer fills short-circuit and succeed with `Ok(())`.
{"case":{"caseId":"case:sha256:bf89fb981bc6e43d44819a85c888b34131283f175c62728ec39c9be169156ff9","contract":["assert getrandom compiles cleanly with --cfg getrandom_backend=\"unsupported\"","assert getrandom::fill fails non-empty buffers with Error::UNSUPPORTED","assert getrandom::u32 and u64 fail with Error::UNSUPPORTED","assert getrandom::fill on empty buffer succeeds with Ok","assert getrandom::fill_uninit on empty buffer succeeds with Ok","assert Error::UNSUPPORTED returns None for raw_os_error"],"goal":"getrandom 0.3 unsupported backend compiles cleanly but fails non-empty fills with Error::UNSUPPORTED while short-circuiting empty slices to Ok","kind":"HOW","packages":["pkg:cargo/getrandom@0.3.4"],"schemaVersion":1,"symbols":["getrandom::fill","getrandom::fill_uninit","getrandom::u32","getrandom::u64","getrandom::Error::UNSUPPORTED","getrandom::Error::raw_os_error","getrandom::Error::new_custom"]},"contractCommand":["cargo","test","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","executionContext":"rust","language":"rust","os":"linux","packageManager":"cargo","runtime":"rust","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/getrandom@0.3.4"],"schemaVersion":1,"symbols":["getrandom::fill","getrandom::fill_uninit","getrandom::u32","getrandom::u64","getrandom::Error::UNSUPPORTED","getrandom::Error::raw_os_error","getrandom::Error::new_custom"],"verifierAdapter":"cargo@1"}
use getrandom::Error;
/// Tries to fill the destination slice with entropy from getrandom.
pub fn try_fill_bytes(dest: &mut [u8]) -> Result<(), Error> {
getrandom::fill(dest)
}
/// Tries to get a random u32 from getrandom.
pub fn try_get_u32() -> Result<u32, Error> {
getrandom::u32()
}
/// Tries to get a random u64 from getrandom.
pub fn try_get_u64() -> Result<u64, Error> {
getrandom::u64()
}
#[cfg(test)]
mod tests {
use super::*;
use core::mem::MaybeUninit;
#[test]
fn test_unsupported_backend_behavior() {
// Non-empty buffer fills fail at runtime with Error::UNSUPPORTED
let mut buf = [0u8; 16];
let err = getrandom::fill(&mut buf).unwrap_err();
assert_eq!(err, Error::UNSUPPORTED);
assert_eq!(err.raw_os_error(), None);
assert_eq!(format!("{err}"), "getrandom: this target is not supported");
// u32 and u64 also fail with Error::UNSUPPORTED
assert_eq!(getrandom::u32().unwrap_err(), Error::UNSUPPORTED);
assert_eq!(getrandom::u64().unwrap_err(), Error::UNSUPPORTED);
// Empty buffer fill short-circuits to Ok(()) without hitting backend
let mut empty_buf = [0u8; 0];
assert!(getrandom::fill(&mut empty_buf).is_ok());
// Empty uninit buffer also short-circuits to Ok(&mut [])
let mut empty_uninit: [MaybeUninit<u8>; 0] = [];
let slice = getrandom::fill_uninit(&mut empty_uninit).unwrap();
assert_eq!(slice.len(), 0);
// Non-empty uninit buffer fails with Error::UNSUPPORTED
let mut uninit_buf = [MaybeUninit::uninit(); 4];
assert_eq!(
getrandom::fill_uninit(&mut uninit_buf).unwrap_err(),
Error::UNSUPPORTED
);
// Custom errors in 0.3 use Error::new_custom with raw_os_error() == None
let custom_err = Error::new_custom(42);
assert_eq!(custom_err.raw_os_error(), None);
assert_eq!(format!("{custom_err}"), "Unknown Error: 131114");
}
}