Skip to content

Commit 94447ba

Browse files
romtsnclaude
andcommitted
fix(security): Verify magic bytes instead of file(1) for trace_processor
The previous check ran `file /tmp/trace_processor | grep -q executable` after downloading the Perfetto trace_processor wrapper. That is unreliable in both directions: - get.perfetto.dev currently serves a Python wrapper script (#!/usr/bin/env python3). Depending on the file(1) version and magic database, shebang scripts may be reported as "Python script, ASCII text" without the word "executable", failing the check. - If Perfetto ever switches to native PIE ELF binaries, older file(1) versions (< 5.36) report them as "shared object" without "executable", also failing. In both cases the valid download was deleted and the workflow aborted. Check magic bytes directly instead — shebang (#!), ELF, or Mach-O — which is stable across platforms and file(1) versions. Also add `curl --fail` so HTTP errors do not leave a partial/HTML response on disk that would then be validated. Refs LINEAR-EME-1060 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c7b4981 commit 94447ba

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

.claude/skills/btrace-perfetto/SKILL.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,23 @@ Before starting, verify:
2222
```
2323
3. **Perfetto trace_processor**: Check if `/tmp/trace_processor` exists. If not, download it:
2424
```bash
25-
# Download trace_processor
26-
curl -sL "https://get.perfetto.dev/trace_processor" -o /tmp/trace_processor
27-
28-
# Verify the file is a valid executable (check file type and size)
29-
if [[ ! -s /tmp/trace_processor ]] || ! file /tmp/trace_processor | grep -q "executable"; then
30-
echo "Error: Downloaded file is not a valid executable"
31-
rm -f /tmp/trace_processor
32-
exit 1
33-
fi
25+
# Download trace_processor (--fail ensures HTTP errors don't leave a file behind)
26+
curl -sSL --fail "https://get.perfetto.dev/trace_processor" -o /tmp/trace_processor
27+
28+
# Verify magic bytes directly — file(1) output is too inconsistent across
29+
# versions/platforms to rely on for scripts or PIE binaries.
30+
magic=$(head -c 4 /tmp/trace_processor 2>/dev/null | od -An -vtx1 -N4 | tr -d ' \n')
31+
case "$magic" in
32+
2321*) ;; # #! shebang (script)
33+
7f454c46) ;; # ELF (Linux)
34+
cffaedfe|cefaedfe|feedfacf|feedface) ;; # Mach-O (macOS)
35+
cafebabe) ;; # Mach-O universal
36+
*)
37+
echo "Error: Downloaded file is not a valid script or executable (magic: ${magic:-empty})"
38+
rm -f /tmp/trace_processor
39+
exit 1
40+
;;
41+
esac
3442

3543
# Make executable only after verification
3644
chmod +x /tmp/trace_processor

0 commit comments

Comments
 (0)