Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

fix(agents): flag a failed signature read and a missing tally

D. Michael Piscitellib10ed932e681
diff --git a/agents/opensource-sanitizer.md b/agents/opensource-sanitizer.md
index be1ac0331..1bb619c2a 100644
--- a/agents/opensource-sanitizer.md
+++ b/agents/opensource-sanitizer.md
@@ -191,7 +191,7 @@ step7_walk() {
continue
fi
label= ctl=
- sig=$(LC_ALL=C dd if="$f" bs=8 count=1 2>/dev/null | od -An -tx1 | tr -d " \n")
+ sig=$(set -o pipefail; LC_ALL=C dd if="$f" bs=8 count=1 2>/dev/null | od -An -tx1 | tr -d " \n") || sig=
case $sig in
504b0304*|504b0506*|504b0708*) label="ZIP/OOXML container (PK: docx, xlsx, pptx, odt, jar)";;
d0cf11e0a1b11ae1*) label="OLE compound document (legacy doc/xls/ppt/msi)";;
@@ -277,8 +277,15 @@ step7_walk | {
if [ -z "$ended" ]; then
problems=$((problems + 1)); echo "Scan problem: the walk ended early, so some files were not checked"
fi
- # Tally by type, from the second column only.
- [ "$n" -eq 0 ] || { cut -f2 "$manifest" | LC_ALL=C sort | uniq -c; } 2>/dev/null
+ # Tally by type, from the second column only. It needs cut, sort and uniq; the count does not.
+ if [ "$n" -gt 0 ]; then
+ tally=$({ cut -f2 "$manifest" | LC_ALL=C sort | uniq -c; } 2>/dev/null)
+ if [ -n "$tally" ]; then
+ printf "%s\n" "$tally"
+ else
+ echo "No tally: cut, sort or uniq is missing. The count is unaffected."
+ fi
+ fi
if [ "$problems" -gt 0 ]; then
echo "Unreadable count: unknown ($n listed, $problems scan problems)"
else
@@ -346,8 +353,9 @@ Generate `SANITIZATION_REPORT.md` in the project directory:
- 1 PDF
- 1 ZIP/OOXML container (PK: docx, xlsx, pptx, odt, jar)
-{One bullet per tally line Step 7 printed, as above, then each `Scan problem:` line it printed. If
-the count is unknown, or Step 7 printed no count, say the scan did not finish.}
+{One bullet per tally line Step 7 printed, as above, or its `No tally` line, then each
+`Scan problem:` line it printed. If the count is unknown, or Step 7 printed no count, say the scan
+did not finish.}
The pipeline gate acts on this count, not on the verdict. The paths are in
`{project-dir}.UNREADABLE_FILES.txt`, beside the project directory, and this section carries no
diff --git a/tests/skills/sanitizer-unreadable.test.js b/tests/skills/sanitizer-unreadable.test.js
index 039c8ea49..e41672f6c 100644
--- a/tests/skills/sanitizer-unreadable.test.js
+++ b/tests/skills/sanitizer-unreadable.test.js
@@ -523,14 +523,27 @@ run('tr or cmp missing: scan problem and unknown count', () => {
});
// 12. sort missing ----------------------------------------------------------------------------------
-run('sort missing: the count line is still printed and correct', () => {
- const root = makeTemp('san-nosort-');
- write(root, 'book.docx', SIG.pk03);
+run('sort, cut or uniq missing: the count is still correct and the missing tally is said out loud', () => {
+ for (const tool of ['sort', 'cut', 'uniq']) {
+ const root = makeTemp('san-notally-');
+ write(root, 'book.docx', SIG.pk03);
+ write(root, 'doc.pdf', SIG.pdf);
+ write(root, 'plain.txt', 'hello\n');
+ const r = scan(root, makeBin({ omit: [tool] }));
+ assert.strictEqual(r.count, '2', tool + ': ' + r.stdout);
+ assert.strictEqual(r.records.length, 2);
+ assert.ok(r.lines.some((l) => l.startsWith('No tally: ')), tool + ': a missing tally must not be silent: ' + r.stdout);
+ }
+});
+
+run('a signature read that fails after one byte lists the file as unverified, not as a short text file', () => {
+ const root = makeTemp('san-sigfail-');
write(root, 'doc.pdf', SIG.pdf);
- write(root, 'plain.txt', 'hello\n');
- const r = scan(root, makeBin({ omit: ['sort'] }));
- assert.strictEqual(r.count, '2');
- assert.strictEqual(r.records.length, 2);
+ // dd stand-in: hand over the first byte, then fail
+ const bin = makeBin({ shims: { dd: 'for a in "$@"; do case $a in if=*) f=${a#if=} ;; esac; done\nIFS= read -r -n 1 c < "$f"\nprintf %s "$c"\nexit 1' } });
+ const r = scan(root, bin);
+ assert.strictEqual(r.count, '1', r.stdout);
+ assert.strictEqual(labelOf(r, 'doc.pdf'), 'detector error, unverified');
});
// Manifest location ---------------------------------------------------------------------------------