Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
85c9f88
feat(rust): read cargo-auditable dependencies from WebAssembly modules
yu0809 Oct 18, 2026
9bac2e3
fix(rust): bound the WebAssembly section walk
yu0809 Oct 18, 2026
cda31a6
Merge morluto/rea main into feat/rust-wasm-auditable
yu0809 Oct 18, 2026
162590b
Merge origin/main into feat/rust-wasm-auditable
kaoru0822-kitauji Oct 21, 2026
345f0f4
Merge morluto/rea main into feat/rust-wasm-auditable
yu0809 Oct 21, 2026
d2fd725
fix(rust): accept WebAssembly Evidence in retained dependency views
yu0809 Oct 21, 2026
bdb41d2
fix(rust): name the WebAssembly section-walk allowance in recovery
yu0809 Oct 21, 2026
6ce932e
Merge morluto/rea main into feat/rust-wasm-auditable
yu0809 Oct 25, 2026
084ad35
fix(rust): require WebAssembly container facts in reports
yu0809 Oct 25, 2026
a86deb1
Merge morluto/rea main into feat/rust-wasm-auditable
yu0809 Nov 17, 2026
8865878
docs(rust): record the WebAssembly dependency-metadata feature
yu0809 Nov 17, 2026
e88658c
fix(rust): bind section names to containers and share the LEB128 reader
yu0809 Nov 17, 2026
bb745a3
fix(rust): classify a cut-off WebAssembly integer by its boundary
yu0809 Nov 17, 2026
3753f11
fix(rust): report a duplicate WebAssembly dependency section first
yu0809 Nov 17, 2026
fb270a2
Merge remote-tracking branch 'origin/main' into feat/rust-wasm-auditable
cursoragent Nov 18, 2026
b6510e5
test(rust): assert WebAssembly container facts instead of limitation …
cursoragent Nov 18, 2026
d8b8f22
fix(rust): state container word size as 32 | 64 | null
cursoragent Nov 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(rust): bind section names to containers and share the LEB128 reader
The report schema accepted a dependency section name that does not belong
to the report's container, such as a WebAssembly report naming the Mach-O
section. rustDependencySectionName now owns that name for the reader and
the schema, which refuses a mismatch for every container.

The WebAssembly reader decoded section sizes with its own loop. It now
uses the shared readLeb128, and an integer cut off by the end of the file
is truncated rather than malformed.
  • Loading branch information
yu0809 committed Nov 17, 2026
commit e88658c2ceb9874e271ece585f64bc89cc3cb21f
9 changes: 5 additions & 4 deletions docs/rust-binaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,11 @@ The report's `format` and `architecture` are `wasm` and its `byte_order` is
memory address types are not inspected. The Evidence subject format is
`file`, as for `inspect_wasm_artifact`.

A header or section that ends past the file is truncated. A custom-section
name that extends past its section, a size that is not a 32-bit LEB128
integer, a custom-section name that is not UTF-8, a second `.dep-v0` section,
or a second data section is malformed. Both are invalid input. WebAssembly
A header, section or section size that ends past the file is truncated. A
custom-section name or name length that extends past its section, a size that
does not fit a 32-bit LEB128 integer, a custom-section name that is not UTF-8,
a second `.dep-v0` section, or a second data section is malformed. Both are
invalid input. WebAssembly
components, such as `wasm32-wasip2` output, embed several core modules. They
are unsupported: no input selects one embedded module the way `architecture`
selects a universal Mach-O slice.
Expand Down
10 changes: 6 additions & 4 deletions docs/specs/native/rust-wasm-auditable/plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
## Boundary and contract

`src/rust/RustWasmImage.ts` owns WebAssembly section framing: the preamble,
layer and version, LEB128 section sizes, custom-section names, the `.dep-v0`
payload ranges and the data-section range. It reports failures through the
layer and version, section sizes read with the shared `readLeb128`,
custom-section names, the `.dep-v0` payload ranges and the data-section range. It reports failures through the
`ParseFailure` algebra with format `wasm`, and the section bound as a
`max_wasm_sections` decode limit.

Expand All @@ -15,8 +15,10 @@ from `RustWasmImage`. The dependency decoder, PE alignment allowance and rustc
path retention are shared and unchanged.

`src/domain/rust/rustBinary.ts` owns the report contract: `format` gains
`wasm`, `bits` is nullable, and refinements bind `bits`, `architecture` and
`byte_order` to the container. `metadataReportSubjectFormat` in
`wasm`, `bits` is nullable, and refinements bind `bits`, `architecture`,
`byte_order` and the dependency section name to the container.
`rustDependencySectionName` is the one owner of that name for the reader and
the schema. `metadataReportSubjectFormat` in
`src/domain/apple/machoTargetSelection.ts` maps a `wasm` report to the `file`
subject, and `requireMetadataReportSubject` accepts it, so the service, the
retained views and the CycloneDX view agree on one mapping.
Expand Down
18 changes: 11 additions & 7 deletions docs/specs/native/rust-wasm-auditable/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ implementation already had; no earlier plan is reconstructed.
2. A version 1 core module is accepted. A component (layer 1) and any other
module version are unsupported targets, because a component embeds several
core modules and no input selects one.
3. A custom section named `.dep-v0` supplies the dependency list.
`file_offset` and `section_bytes` locate the payload after the section
name, in the original file. A second `.dep-v0` section is malformed.
3. A custom section named `.dep-v0` supplies the dependency list, and the
report's `section_name` is `.dep-v0`; the report schema binds each
container to its section name. `file_offset` and `section_bytes` locate the
payload after the section name, in the original file. A second `.dep-v0`
section is malformed.
4. A missing `.dep-v0` section is null metadata with a limitation. It is not
evidence that the module has no dependencies.
5. `format` and `architecture` are `wasm` and `byte_order` is `little`.
Expand All @@ -39,9 +41,11 @@ implementation already had; no earlier plan is reconstructed.
6. The rustc commit is inferred from `/rustc/<40-hex>/` paths in the module's
data section. Limitations name that source. A second data section is
malformed.
7. A header or section that ends past the file is truncated. A section size or
name length that is not a 32-bit LEB128 integer, a custom-section name that
extends past its section, and a name that is not UTF-8 are malformed.
7. A header, section or section size that ends past the file is truncated. A
size or name length that does not fit a 32-bit LEB128 integer, a
custom-section name or name length that extends past its section, and a
name that is not UTF-8 are malformed. Integers are decoded by the shared
LEB128 reader.
8. The section walk stops after 65,536 sections with a `cpu` resource
constraint. The format sets no section count and the walk is synchronous.
The allowance is fixed; `producer_limits` does not raise it. Retained state
Expand All @@ -65,7 +69,7 @@ implementation already had; no earlier plan is reconstructed.
schema and check the section-bound refusal through the public error
contract.
- A view test refuses imported reports whose container facts contradict
requirement 5.
requirements 3 and 5.

## Non-goals

Expand Down
15 changes: 14 additions & 1 deletion src/domain/analysisView/rustBinaryView.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,18 @@ it("checks exact artifact identity and subject architecture for every Rust view"
}
});

it("refuses imported reports whose container facts contradict WebAssembly", () => {
const withSectionName = (
value: RustBinary,
section_name: NonNullable<RustBinary["auditable_metadata"]>["section_name"],
): RustBinary => ({
...value,
auditable_metadata:
value.auditable_metadata === null
? null
: { ...value.auditable_metadata, section_name },
});

it("refuses imported reports whose container facts contradict their format", () => {
const wasm: RustBinary = {
...structuredClone(report),
format: "wasm",
Expand All @@ -157,6 +168,8 @@ it("refuses imported reports whose container facts contradict WebAssembly", () =
{ ...wasm, byte_order: "big" as const },
{ ...wasm, bits: 32 as const },
{ ...structuredClone(report), architecture: "wasm" },
withSectionName(wasm, "__DATA,.dep-v0"),
withSectionName(structuredClone(report), "__DATA,.dep-v0"),
])
expect(projectAnalysisView(parent(value), { kind: "summary" }).ok).toBe(
false,
Expand Down
16 changes: 15 additions & 1 deletion src/domain/rust/rustBinary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@ const dependencyEdgeSchema = z.strictObject({
to_index: index,
});

const DEPENDENCY_SECTION_NAMES = [".dep-v0", "__DATA,.dep-v0"] as const;

/** The dependency section's name in a container: Mach-O qualifies it with its segment. */
export const rustDependencySectionName = (
format: "elf" | "pe" | "macho" | "wasm",
): (typeof DEPENDENCY_SECTION_NAMES)[number] =>
format === "macho" ? "__DATA,.dep-v0" : ".dep-v0";

/** zlib JSON from one `.dep-v0` section, in the section's package order. */
export const rustAuditableMetadataSchema = z.strictObject({
section_name: z.enum([".dep-v0", "__DATA,.dep-v0"]),
section_name: z.enum(DEPENDENCY_SECTION_NAMES),
file_offset: index,
/** Stored section range, including accepted PE file-alignment bytes. */
section_bytes: z.int().positive(),
Expand Down Expand Up @@ -181,6 +189,12 @@ export const rustBinarySchema = z
issue(context, ["byte_order"], "A WebAssembly module is little-endian.");
Comment thread
yu0809 marked this conversation as resolved.
Resolved
const metadata = report.auditable_metadata;
if (metadata !== null) {
if (metadata.section_name !== rustDependencySectionName(report.format))
issue(
context,
["auditable_metadata", "section_name"],
"Dependency section name does not belong to the report's container.",
);
checkSection(report.artifact.bytes, metadata, context);
checkPackages(metadata, context);
}
Expand Down
6 changes: 3 additions & 3 deletions src/rust/RustBinaryImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
import {
DEFAULT_RUSTC_HASH_LIMIT,
rustcPartialCoverage,
rustDependencySectionName,
} from "../domain/rust/rustBinary.js";
import { RUST_PRODUCER_DEFAULTS } from "../domain/rust/rustResourceLimits.js";
import {
Expand Down Expand Up @@ -89,8 +90,7 @@ export const readRustBinaryImage = (

const nativeLayout = (bytes: Buffer): RustImageLayout => {
const container = readContainer(bytes);
const section_name =
container.format === "macho" ? "__DATA,.dep-v0" : ".dep-v0";
const section_name = rustDependencySectionName(container.format);
const dependency = dependencySection(section_name, container.sections);
return {
format: container.format,
Expand Down Expand Up @@ -135,7 +135,7 @@ const wasmLayout = (bytes: Buffer): RustImageLayout => {
architecture: "wasm",
bits: null,
byte_order: "little",
section_name: ".dep-v0",
section_name: rustDependencySectionName("wasm"),
dependency: dependency_sections[0] ?? null,
compiler_strings: data_section === null ? [] : [data_section],
};
Expand Down
29 changes: 18 additions & 11 deletions src/rust/RustWasmImage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isUtf8 } from "node:buffer";
import { readLeb128, ULEB32 } from "../domain/leb128.js";
import {
decodeLimit,
malformedInput,
Expand Down Expand Up @@ -128,24 +129,30 @@ const customSection = (
return { name, payload };
};

/** Decode one unsigned LEB128 u32, which the binary format bounds to five bytes. */
/**
* Decode one unsigned LEB128 u32 that must end before `end`. An integer the
* file cuts off is truncated; one its enclosing section cuts off is malformed.
*/
const readU32 = (
bytes: Buffer,
offset: number,
end: number,
label: string,
): { readonly value: number; readonly end: number } => {
let value = 0;
for (let index = 0; index < 5 && offset + index < end; index += 1) {
const byte = bytes[offset + index]!;
// The fifth byte may only carry the four remaining bits and no continuation.
if (index === 4 && byte > 0x0f) break;
value += (byte & 0x7f) * 2 ** (7 * index);
if ((byte & 0x80) === 0) return { value, end: offset + index + 1 };
}
const read = readLeb128(bytes, offset, end, ULEB32);
if ("value" in read) return { value: Number(read.value), end: read.next };
const site = { offset, field: label };
if (read.failure === "truncated" && end === bytes.length)
Comment thread
yu0809 marked this conversation as resolved.
Resolved
throw truncatedInput(
WASM_FORMAT,
`WebAssembly ${label} extends past the end of the file`,
site,
);
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Resolved
throw malformedInput(
WASM_FORMAT,
`WebAssembly ${label} is not a complete 32-bit LEB128 integer`,
{ offset, field: label },
read.failure === "truncated"
? `WebAssembly ${label} extends past its section`
: `WebAssembly ${label} does not fit a 32-bit LEB128 integer`,
site,
);
};
19 changes: 19 additions & 0 deletions tests/boundary/rust/rustBinaryImage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,25 @@ it.each([
Buffer.concat([WASM_MODULE_HEADER, Buffer.from([0x01, 0x05, 0x00])]),
{ kind: "truncated", format: "wasm", offset: 8, field: "section" },
],
[
"a section size cut off by the end of the file",
Buffer.concat([WASM_MODULE_HEADER, Buffer.from([0x00, 0x80])]),
{ kind: "truncated", format: "wasm", offset: 9, field: "section size" },
],
[
"a custom name length cut off by its section",
Buffer.concat([
WASM_MODULE_HEADER,
wasmSection(0, Buffer.from([0x80])),
wasmSection(1, Buffer.from([0x00])),
]),
{
kind: "malformed",
format: "wasm",
offset: 10,
field: "custom section name length",
},
],
[
"a section size over 32 bits",
Buffer.concat([
Expand Down