Repository navigation
Make content sniffing trim-safe - #1398
Merged
Merged
Conversation
`_SNIFF_SIGNATURES` was an `Any[...]` vector, so every `_sniff_match` and `_sniff_content_type` call in the `sniff` loop dispatched at runtime, which `juliac --trim=safe` rejects. Type the table as a three-member union and check the three trailing data-free signatures (MP4, JSON, text) from a tuple afterwards. Both loops stay within inference's union-splitting limit, so dispatch is static. Signature order is unchanged. The open-fileserver trim workload now calls `servecontent` without a content type and `HTTP.sniff` directly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1398 +/- ##
==========================================
- Coverage 90.80% 90.79% -0.02%
==========================================
Files 31 31
Lines 12835 12838 +3
==========================================
+ Hits 11655 11656 +1
- Misses 1180 1182 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HTTP.sniff, andservecontentwithout acontent_type(or anamewith a known extension), failedjuliac --trim=safeon Julia 1.13.1 with three verifier errors:HTTP._sniff_match(::Any, data, ::Int64)HTTP._sniff_content_type(::Any)convert(String, ::Any)Root cause:
_SNIFF_SIGNATURESwas anAny[...]vector, so each call in thesniffloop dispatched at runtime. The table holds six signature types, more than inference will union-split (four), so giving it a concrete element type alone isn't enough.Fix: the table is now
Union{_SniffHTMLSig,_SniffMasked,_SniffExact}[...]. The three data-free signatures that always ran last (MP4, JSON, text) move to a tuple thatsniffchecks after the table. Both loops have three types, so dispatch is static. Signature order and results are unchanged.Coverage:
test/http_trim_open_fileserver.jlnow callsservecontentwith bytes and no content type, plusHTTP.sniffon a string, and checks the results. That workload runs the built executable, so the content types are also checked at runtime.Found while reviewing #1397, whose router workload passes
content_typeexplicitly to avoid this gap.Verification (Julia 1.13.1, macOS arm64)
srcchange reverted: 12 verifier errors, all the three sniff calls above (once each for theVectorandSubArrayinputs, via both callers).sniffon 25,371 inputs (every signature with whitespace, case, and suffix variants, plus random bytes up to 600 long), as bothVectorand view: 0 mismatches, 27 distinct content types.http_forms_tests.jl,http_multipart_tests.jl,http_server_http1_tests.jl,public_api_tests.jl: 909/909 pass.Not in this PR
servecontent(request, io)with anIOsource and nosizestill fails trim:_source_sizeformats a caught error withsprint(showerror, err), which adds about 18 verifier errors. That's a separate change.🤖 Generated with Claude Code