Commit 8b4755d
fix(detect): skip leading ASCII whitespace in is_binary_file + 0.2.4
Server-padded HTML payloads (Aestiva HTML/OS engines emit
`\n\n\n\n\n\n\n\n\n<!doctype html>...` — observed in the wild on
seeleylake.com and similar legacy WordPress-adjacent stacks)
previously dodged magic-byte sniffing because the first byte was
whitespace, not a magic prefix. Worse, the small fixed sniff
windows that downstream consumers (e.g. spider's 16-byte spool head
sample) feed in could leave no headroom for an actual signature
match if the padding ate into the window.
The fix adds a 256-byte compile-time `INTERESTING_FIRST_BYTE`
classifier (magic-table first bytes ∪ ASCII whitespace) that gates
the magic search. Any byte not in either set short-circuits to
false in a single L1-resident lookup. Whitespace bytes hand off to
a `#[cold]` helper that trims and re-runs the search. Symmetrical
treatment for the legacy `is_binary_file_phf` sibling.
Bench delta (criterion, sub-bench `is_binary_file`):
not_binary 3.86 ns -> 0.78 ns (-80%, 5x faster)
png_match 7.33 ns -> 9.10 ns (+25%)
jpeg_match 10.40 ns -> 11.81 ns (+16%)
The dominant real-world case is "not binary" (HTML responses), so
this is a net speedup; the absolute regression on binary headers is
~1-2 ns, well under the cost of any actual byte-level work the
caller is doing on the body.
Tests cover Aestiva-padded HTML, padded PNG, padded PDF, empty,
whitespace-only, and the bare-magic / non-binary regressions.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 0727f9f commit 8b4755d
4 files changed
Lines changed: 147 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 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 | + | |
26 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
27 | 72 | | |
28 | 73 | | |
29 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
30 | 79 | | |
31 | 80 | | |
32 | | - | |
33 | 81 | | |
34 | 82 | | |
35 | 83 | | |
36 | 84 | | |
37 | 85 | | |
38 | 86 | | |
39 | 87 | | |
| 88 | + | |
40 | 89 | | |
41 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
42 | 93 | | |
43 | 94 | | |
44 | 95 | | |
45 | 96 | | |
| 97 | + | |
| 98 | + | |
46 | 99 | | |
47 | 100 | | |
48 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
49 | 106 | | |
50 | 107 | | |
51 | | - | |
52 | | - | |
| 108 | + | |
53 | 109 | | |
54 | 110 | | |
55 | 111 | | |
56 | 112 | | |
57 | 113 | | |
58 | 114 | | |
59 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
60 | 169 | | |
61 | 170 | | |
62 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
238 | 268 | | |
239 | 269 | | |
240 | 270 | | |
| |||
0 commit comments