mirror of
https://github.com/qybaihe/bla.git
synced 2026-11-20 08:20:59 +08:00
fix(lint-lanes): ignore all-zero init arrays as compare tables
Round-2 blue whole-key pack buffers like [0,0,0,0] tripped per-lane-byte-compare-array next to key identifiers. Skip all-zero literals so chained gates harden under default refuse without allow.
This commit is contained in:
@@ -82,13 +82,18 @@ export function lintLaneIndependence(source: string): LaneIndependenceReport {
|
||||
|
||||
if (BYTE_COMPARE_ARRAY.test(text) && /(?:key|guess|input|lane)/i.test(text)) {
|
||||
const m = text.match(BYTE_COMPARE_ARRAY);
|
||||
findings.push(
|
||||
finding(
|
||||
"per-lane-byte-compare-array",
|
||||
"Literal multi-byte compare table near key/guess identifiers — may allow independent per-lane probes.",
|
||||
m?.[0] ?? "",
|
||||
),
|
||||
);
|
||||
// Round-2 blue: all-zero init arrays (e.g. pack buffers) are not compare tables.
|
||||
const lit = m?.[0] ?? "";
|
||||
const allZero = /^\[\s*0\s*(?:,\s*0\s*){3,}\]$/.test(lit);
|
||||
if (!allZero) {
|
||||
findings.push(
|
||||
finding(
|
||||
"per-lane-byte-compare-array",
|
||||
"Literal multi-byte compare table near key/guess identifiers — may allow independent per-lane probes.",
|
||||
lit,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (LANE_AND_REDUCE.test(text) || EVERY_INDEXED_LANE.test(text)) {
|
||||
|
||||
@@ -59,6 +59,30 @@ describe("lane-independence footgun lint (#40.1 / red-blue round-1)", () => {
|
||||
expect(report.findings[0]!.severity).toBe("error");
|
||||
});
|
||||
|
||||
it("ignores all-zero init arrays used for whole-key packing (round-2 blue)", () => {
|
||||
const src = `
|
||||
function packWord(key, start) {
|
||||
let w = 0;
|
||||
for (let i = 0; i < 4; i++) w = (w << 8) | key.charCodeAt(start + i);
|
||||
return w | 0;
|
||||
}
|
||||
function activate(key) {
|
||||
let a = packWord(key, 0), b = packWord(key, 4), c = packWord(key, 8), d = packWord(key, 12);
|
||||
// legacy-looking zero buffer that is NOT a compare table:
|
||||
const scratch = [0, 0, 0, 0];
|
||||
void scratch;
|
||||
for (let r = 0; r < 24; r++) {
|
||||
a = (a + b) | 0; b = (b ^ a) | 0; c = (c + d) | 0; d = (d ^ c) | 0;
|
||||
a ^= c; b ^= d;
|
||||
}
|
||||
return (a ^ b ^ c ^ d) === 0x12345678;
|
||||
}
|
||||
`;
|
||||
const report = lintLaneIndependence(src);
|
||||
expect(report.findings.some((f) => f.id === "per-lane-byte-compare-array")).toBe(false);
|
||||
expect(report.looksLaneIndependent).toBe(false);
|
||||
});
|
||||
|
||||
it("errors on CrackMe v6-style per-byte WASM lane oracles", () => {
|
||||
const tpl = readFileSync(
|
||||
resolve(process.cwd(), "challenge/v6/src/vault.template.cjs"),
|
||||
|
||||
Reference in New Issue
Block a user