unionlabs/union · error
parsing rev
Error message
parsing rev
What it means
extract_elf reads the .note.embed_commit.GIT_REV ELF section and reinterprets its first size_of::<Rev>() (32) bytes as the Rev enum (discriminant for unknown/dirty plus a 20-byte hash). bytemuck's checked cast fails when those bytes are not a valid Rev bit pattern — typically an unknown discriminant byte — and the anyhow context "parsing rev" wraps the failure.
Source
Thrown at lib/embed-commit/verifier/src/lib.rs:38
///
/// This function will error if the elf binary bytes provided cannot be parsed, or if the embedded git rev cannot be parsed. If there is no embedded git rev then `Ok(None)` will be returned.
pub fn extract_elf(bz: &[u8]) -> Result<Option<Rev>> {
let file = ElfBytes::<AnyEndian>::minimal_parse(bz).context("parsing elf file")?;
let Some(section) = file
.section_header_by_name(".note.embed_commit.GIT_REV")
.context("reading GIT_REV note section")?
else {
return Ok(None);
};
let (bytes, _) = file
.section_data(§ion)
.context("reading GIT_REV note section data")?;
bytemuck::checked::try_from_bytes::<Rev>(&bytes[0..std::mem::size_of::<Rev>()])
.map_err(|e| anyhow!(e.to_string()))
.context("parsing rev")
.map(|rev| Some(*rev))
}
/// Retrieve the git rev from the provided wasm binary bytes.
///
/// # Errors
///
/// This function will error if the wasm binary bytes provided cannot be parsed, or if the returned git rev cannot be parsed. If there is no `commit_hash` export then `Ok(None)` will be returned.
pub fn extract_wasm(bz: &[u8]) -> Result<Option<Rev>> {
let engine = Engine::default();
let module = Module::from_binary(&engine, bz)?;
let mut linker = Linker::new(&engine);
let mut store: Store<()> = Store::new(&engine, ());
// stub all imports as they're unused when evaluating commit_hash
for import in module.imports() {
linker.func_new(
import.module(),View on GitHub (pinned to 031785bb6d)
Solutions
- Rebuild the artifact with the union embed-commit toolchain so the note is well-formed
- Confirm you are inspecting the intended binary and inspect the section: readelf -x .note.embed_commit.GIT_REV <file>
- Align the verifier's embed-commit crate version with the producer's
- Treat parse failure as 'unrecognized producer' and report the underlying PodCastError rather than retrying
Example fix
// before
bytemuck::checked::try_from_bytes::<Rev>(&bytes[0..std::mem::size_of::<Rev>()])
.map_err(|e| anyhow!(e.to_string()))
.context("parsing rev")
// after — distinguish truncation from an invalid bit pattern
let need = std::mem::size_of::<Rev>();
if bytes.len() < need {
anyhow::bail!("GIT_REV note too short: {} < {need}; binary not built by embed-commit", bytes.len());
}
let rev = bytemuck::checked::try_from_bytes::<Rev>(&bytes[..need])
.map_err(|e| anyhow!("invalid GIT_REV bit pattern ({e:?}); binary not built by embed-commit"))?
.clone(); Defensive patterns
Strategy: validation
Validate before calling
// Validate the note before the checked cast
let need = std::mem::size_of::<Rev>();
if bytes.len() < need { /* too short: not an embed-commit ELF */ }
let tag = bytes[0]; // discriminant byte for the repr(u8) Rev layout
if tag > 2 { /* invalid discriminant: foreign or corrupted producer */ } Type guard
fn as_rev(bytes: &[u8]) -> Option<Rev> {
if bytes.len() < std::mem::size_of::<Rev>() {
return None;
}
bytemuck::checked::try_from_bytes::<Rev>(&bytes[..std::mem::size_of::<Rev>()])
.ok()
.map(|r| *r)
} Prevention
- Rebuild artifacts with the union toolchain whenever the note fails to parse
- Check section presence and size with readelf before verifying
- Never hand-craft .note.embed_commit.GIT_REV sections
- Pin matching embed-commit crate versions across build and verify environments
When it happens
Trigger: Verifying an ELF whose GIT_REV note section exists but was written by a different producer/version or is corrupted: an invalid tag byte, a section produced with a different Rev layout, or bytes garbled by post-build processing. (A section shorter than 32 bytes instead panics at slicing before reaching this error.)
Common situations: Binaries rebuilt or patched after the note was embedded; a different toolchain writing a same-named section; embed-commit version drift between the builder that embedded the note and the verifier parsing it.
Related errors
AI-assisted analysis of unionlabs/union@031785bb6d (2026-08-16).
Data as JSON: /api/errors/f7baf9b1d3771c95.
Report an issue: GitHub.