fix(rizin): bound the version banner as printed before trimming it

The probe trimmed the first line before applying its 2,048-byte budget,
so a line with more than 2,048 bytes of leading whitespace before a
valid banner lost that prefix unrecorded and was identified, with
provider_version_banner_truncated false, although the documented budget
covers the banner line. The budget and the recorded banner now cover
the line as printed; only identification reads a trimmed copy.
This commit is contained in:
Entrpi committed 2026-11-01 16:07:20 +11:00
1 parent 1a9af35de7
commit 7ce99121bb
3 files changed
+35 -4

No files matched your search

+3 -1
View File
@@ -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
@@ -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
? {
@@ -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 () => {