Repository navigation
fix(router): stop trusting two bytes, and a cut that lands mid-character - #1
Merged
Merged
Conversation
Two ways the router sent a file to the wrong pipeline. `BM` is a two-byte signature, so `BMW service history.txt` was routed to the image pipeline and failed to open. The BMP check now corroborates the header: both reserved words zero and a DIB header size from the set every writer uses. A real BMP is unaffected. The text sniff cut at 512 bytes and required that slice to be valid UTF-8. When byte 512 landed inside a multi-byte character, good text looked binary — with no extension it fell through to `Unknown`, and the file would not open at all. The cut now steps back to the last character boundary. Three tests: the two false routes (both fail on the old code) and a real BMP header that must keep routing to the image pipeline.
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.
What I read
crates/feather-core/src/format.rs(the router),natural.rs, the CLI'sinfo/render, the workspaceCargo.toml,ROADMAP.md,docs/decisions.md, and.github/workflows/ci.yml. The router decides once, from bytes, with the extension as a tie-breaker for zip containers.What was wrong
Two routes that send a file to a pipeline that cannot open it.
BMis two bytes. Any file beginning with those two bytes went to the image pipeline.BMW service history.txtis a text file; the viewer would fail to open it.Unknownand would not open at all.What I changed
is_bmp()corroborates the BMP signature with the rest of the header: both reserved words zero, and a DIB header size from the set every BMP writer emits (12, 40, 52, 56, 64, 108, 124). A real BMP still routes to the image pipeline, unchanged.The 512-byte cut now steps back to the last valid character boundary before asking whether the bytes are text. The classification logic after it is untouched.
Evidence
Three tests, added to the existing
format.rsmodule —a_text_file_beginning_with_bm_is_not_a_bitmap,a_real_bmp_header_is_still_an_image,a_character_split_at_the_cut_does_not_make_text_binary. The first and third fail onmain; the second is the guard that the fix did not break real bitmaps.CI on this PR runs
cargo test --workspace(71 tests before, 74 after) plus the release build and the M0 render smoke test on three platforms — the run is the evidence, not this text.What I deliberately did not do
ROADMAP.mdputs v0.2 (skrifa/harfrust/unicode-bidi) and v0.3 (PDF text extraction) behind "a compiler in the loop", and it is right to: that is rasterisation, fallback and glyph caching, not a slice to write blind. I have no Rust toolchain here —static.rust-lang.orgis unreachable — so CI is my only compiler, and I will not spend your CI cycles guessing at a half-migrated text stack.feather-cli(two subcommands, hand-rolled, and this repo gates its dependency budget);pdf.js,pdfjs-distandPyMuPDFare other languages againsthayro;ripgrep-allshells out to external binaries, which a single-binary viewer cannot do;mcat,crosstermandratatuiare terminal rendering, and this window iswinit+softbuffer;pdfcpuandsumatrapdfare a Go tool and a C++ Windows app — the ideas worth having from them (structural validation, startup ordering) are features, not slices, and they are in the roadmap's own queue.