gstack-redact says that input over 16 MiB is always refused (#4351) (#4373)

gstack-redact refuses any input over 16 MiB before --max-bytes is read, so
a bigger --max-bytes never helped and nothing said so. --help and both
"too large" errors now name the 16 MiB limit, say --max-bytes can't raise
it, and suggest splitting the input. The help's exit line also says that
exit 3 covers input that is too large. What gets scanned, what gets
redacted, the exit codes and where output goes are unchanged.

Rebuilt on main from #4352.

Co-authored-by: ElNeMeR70 <83190847+ElNeMeR70@users.noreply.github.com>
Co-authored-by: exGeni <135786749+exGeni@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-15 01:32:03 +00:00
1 parent 81fb900835
commit 3805969159
3 files changed
+47 -4

No files matched your search

+13 -4
View File
@@ -22,6 +22,8 @@
* --auto-redact IDS Comma-separated finding ids to auto-redact;
* prints the redacted body to stdout + diff to stderr.
* --max-bytes N Override the fail-closed size cap (default 1 MiB).
* Input over 16 MiB is always refused; --max-bytes
* can't raise that ceiling, so split larger input.
*
* Security note: this is a GUARDRAIL, not airtight enforcement. A determined
* user can always bypass it (direct gh/git). It catches accidents.
@@ -39,7 +41,11 @@ import {
} from "../lib/redact-engine";
import { mkdirpSync } from "../lib/fs-utils";
const MAX_STDIN_BYTES = 16 * 1024 * 1024; // hard ceiling before the engine cap
const MAX_STDIN_MIB = 16;
const MAX_STDIN_BYTES = MAX_STDIN_MIB * 1024 * 1024; // hard ceiling before the engine cap
const CEILING_NOTE =
`The limit is ${MAX_STDIN_MIB} MiB and --max-bytes can't raise it. ` +
"Split the input and scan the parts.";
// ── pre-push hook install/uninstall (chains any existing hook) ────────────────
@@ -156,7 +162,7 @@ function readInput(): string {
const st = fs.statSync(file);
if (st.size > MAX_STDIN_BYTES) {
// Don't even read it — fail closed at the CLI boundary.
process.stderr.write(`gstack-redact: input file too large (${st.size} bytes)\n`);
process.stderr.write(`gstack-redact: input file too large (${st.size} bytes). ${CEILING_NOTE}\n`);
process.exit(3);
}
return fs.readFileSync(file, "utf8");
@@ -178,7 +184,7 @@ function readInput(): string {
if (n === 0) break;
total += n;
if (total > MAX_STDIN_BYTES) {
process.stderr.write("gstack-redact: stdin too large\n");
process.stderr.write(`gstack-redact: stdin too large. ${CEILING_NOTE}\n`);
process.exit(3);
}
chunks.push(Buffer.from(buf.subarray(0, n)));
@@ -259,7 +265,10 @@ function printUsage(code: number): never {
" --self-email EMAIL --repo-public-emails PATH --auto-redact IDS\n" +
" --max-bytes N\n" +
"\n" +
"Exit: 0 clean · 1 usage error · 2 MEDIUM present · 3 HIGH present\n",
`--max-bytes N raises the 1 MiB scan cap. Input over ${MAX_STDIN_MIB} MiB is always refused,\n` +
"whatever --max-bytes says; split it and scan the parts.\n" +
"\n" +
"Exit: 0 clean · 1 usage error · 2 MEDIUM present · 3 HIGH present or input too large\n",
);
process.exit(code);
}
@@ -0,0 +1 @@
- `gstack-redact` now says that input over 16 MiB is always refused: `--help` and both `too large` errors name the limit, say `--max-bytes` can't raise it, and suggest splitting the input. Reported by @exGeni (#4351), first fixed by @ElNeMeR70 (#4352).
+33
View File
@@ -102,6 +102,39 @@ describe("gstack-redact oversize fails closed", () => {
expect(code).toBe(3);
expect(stdout).toContain("too large");
});
// #4351: input over the 16 MiB ceiling is refused before --max-bytes is
// consulted, so --help and both errors have to say so.
test("--help names the 16 MiB ceiling that --max-bytes can't raise", () => {
const { code, stdout } = run(["--help"], "");
expect(code).toBe(0);
expect(stdout).toContain("Input over 16 MiB is always refused");
expect(stdout).toContain("3 HIGH present or input too large");
});
test("a --from-file input over 16 MiB names the ceiling even with a bigger --max-bytes", () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "redact-ceiling-"));
try {
const f = path.join(dir, "big.txt");
fs.writeFileSync(f, "");
fs.truncateSync(f, 16 * 1024 * 1024 + 1);
const proc = Bun.spawnSync(["bun", BIN, "--from-file", f, "--max-bytes", "33554432"], {
timeout: 30_000,
});
expect(proc.exitCode).toBe(3);
expect(proc.stderr.toString()).toContain(
"input file too large (16777217 bytes). The limit is 16 MiB and --max-bytes can't raise it.",
);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
test("stdin over 16 MiB names the ceiling even with a bigger --max-bytes", () => {
const { code, stderr } = run(["--max-bytes", "33554432"], "a".repeat(16 * 1024 * 1024 + 1));
expect(code).toBe(3);
expect(stderr).toContain("stdin too large. The limit is 16 MiB and --max-bytes can't raise it.");
});
});
describe("gstack-redact argv dispatch", () => {