diff --git a/docs/reverse-engineering-tools.md b/docs/reverse-engineering-tools.md index 22c2f712b99..710caf368af 100644 --- a/docs/reverse-engineering-tools.md +++ b/docs/reverse-engineering-tools.md @@ -98,7 +98,9 @@ records the tool and version as the provider name and version, and records the executable path, its SHA-256 and the banner in its parameters; a banner longer than 2,048 UTF-8 bytes is cut within that budget, between characters, and marked by `provider_version_banner_truncated`; a cut banner identifies no tool, -since the cut could fall inside its version. These describe the file at that path when +since the cut could fall inside its version. The budget and the recorded banner +cover the line as printed, surrounding whitespace included; only identification +ignores that whitespace. These describe the file at that path when REA checked it; they cannot prove the exact bytes executed if the file changes before the launch. A different tool that accepts the same arguments, such as radare2, still runs: its Evidence names that tool and adds a limitation. A probe diff --git a/src/application/reverse/ReverseEngineeringService.ts b/src/application/reverse/ReverseEngineeringService.ts index 04f56394476..916dd67fc41 100644 --- a/src/application/reverse/ReverseEngineeringService.ts +++ b/src/application/reverse/ReverseEngineeringService.ts @@ -1038,12 +1038,16 @@ export class ReverseEngineeringService { status: "undecodable", diagnostics: versionProbeDiagnostics(0, output), }); - const line = output.stdout.split(/\r?\n/u, 1)[0]?.trim() ?? ""; - const banner = boundedUtf8Text(line, VERSION_PROBE_TEXT_BYTES); + // The budget and the record cover the first line as printed; only + // identification reads it without surrounding whitespace. + const banner = boundedUtf8Text( + output.stdout.split(/\r?\n/u, 1)[0] ?? "", + VERSION_PROBE_TEXT_BYTES, + ); // A cut banner identifies nothing: the cut could fall inside its version. const identification = banner.truncated ? undefined - : probe.identify(banner.text); + : probe.identify(banner.text.trim()); return ok( identification === undefined ? { diff --git a/tests/boundary/filesystem/reverseEngineeringToolIdentity.test.ts b/tests/boundary/filesystem/reverseEngineeringToolIdentity.test.ts index afd0a93c621..8c446554ec7 100644 --- a/tests/boundary/filesystem/reverseEngineeringToolIdentity.test.ts +++ b/tests/boundary/filesystem/reverseEngineeringToolIdentity.test.ts @@ -681,6 +681,31 @@ posix.each([ }, ); +posix.each([ + ["beyond the budget", " ".repeat(2_049), true], + ["within the budget", " ", false], +] as const)( + "bounds a banner's leading whitespace %s as printed before identifying the tool", + async (_case, padding, truncated) => { + const { executable, path } = await rizinExecutableFixture(); + const line = `${padding}rizin 0.9.1 @ linux-x86-64 `; + const run = versionProbeRunner(() => `${line}\n`); + const service = new TestReverseEngineeringService({ + run, + lookup: lookupExecutable, + environment: { REA_RIZIN_COMMAND: executable }, + }); + const result = await service.executeRizinCommand({ path, command: "iI" }); + if (!result.ok) throw result.error; + expect(result.value.provider.version).toBe(truncated ? null : "0.9.1"); + expect(result.value.parameters).toMatchObject({ + provider_version_banner: truncated ? " ".repeat(2_048) : line, + provider_version_banner_truncated: truncated, + provider_identity: truncated ? "assumed" : "banner", + }); + }, +); + posix( "cuts a failed probe's diagnostic streams within 2,048 UTF-8 bytes, between code points", async () => {