GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — panicparse/scripts/lint_binaries.py at main · maruel/panicparse

Expand file tree

/

lint_binaries.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
executable file
·
95 lines (81 loc) · 2.94 KB
/

lint_binaries.py

Copy path

File metadata and controls

executable file
·
95 lines (81 loc) · 2.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
# Copyright 2026 Marc-Antoine Ruel. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.
"""Lint git-tracked files for unexpected binary data and executable files."""
import os
import subprocess
import sys
ALLOWED_BINARY_EXTENSIONS = {
".aac",
".avif",
".br",
".flac",
".gif",
".ico",
".jar",
".jpg",
".mov",
".mp3",
".mp4",
".ogg",
".pdf",
".png",
".svg",
".syso",
".wasm",
".wav",
".webm",
".webp",
".zst",
}
ALLOWED_EXECUTABLE_EXTENSIONS = {".desktop"}
def is_binary(path: str) -> bool:
"""Return whether path contains a null byte near its start."""
if os.path.islink(path) or not os.path.isfile(path):
return False
with open(path, "rb") as f:
return b"\0" in f.read(1024)
def has_executable_preamble(path: str) -> bool:
"""Return whether path starts with a supported executable declaration."""
with open(path, "rb") as f:
first_line = f.readline(256)
# Go generator files use this shell/Go polyglot preamble to run with go run.
return first_line.startswith((b"#!/", b"///usr/bin/true; exec /usr/bin/env go run "))
def tracked_files() -> list[tuple[str, bool]]:
"""Return tracked paths and Git executable modes, including paths with whitespace."""
raw = subprocess.check_output(("git", "ls-files", "--stage", "-z"))
files: list[tuple[str, bool]] = []
for record in raw.split(b"\0"):
if record:
metadata, path = record.split(b"\t", 1)
mode = metadata.split(b" ", 1)[0]
files.append((os.fsdecode(path), mode == b"100755"))
return files
def main() -> int:
"""Report tracked files that are binary or executable without a declaration."""
unexpected_binaries: list[str] = []
unexpected_executables: list[str] = []
for path, executable in tracked_files():
if is_binary(path) and os.path.splitext(path)[1].lower() not in ALLOWED_BINARY_EXTENSIONS:
unexpected_binaries.append(path)
if (
executable
and os.path.isfile(path)
and not os.path.islink(path)
and os.path.splitext(path)[1].lower() not in ALLOWED_EXECUTABLE_EXTENSIONS
and not has_executable_preamble(path)
):
unexpected_executables.append(path)
if unexpected_binaries:
print("Unexpected binary files:", file=sys.stderr)
print(*(f" {path}" for path in unexpected_binaries), sep="\n", file=sys.stderr)
if unexpected_executables:
print(
"Executable files without a shebang, Go launcher preamble, or allowed extension:",
file=sys.stderr,
)
print(*(f" {path}" for path in unexpected_executables), sep="\n", file=sys.stderr)
return int(bool(unexpected_binaries or unexpected_executables))
if __name__ == "__main__":
sys.exit(main())
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.