Store real version and checksum for cached WASM parsers - #741
Open
IzonIcy wants to merge 1 commit into
Open
Conversation
Cached tree-sitter parser entries were written with a hardcoded "1.0.0" version and an empty checksum, so cache metadata carried no useful information and there was no way to detect corrupted downloads. Cache writes now compute a SHA-256 checksum of the WASM bytes via WebCrypto and resolve the parser version from the language extension manifest when one is registered, falling back to "unknown". Both cache write sites share a single entry builder instead of duplicating the record shape. Cache reads verify the stored checksum and treat a mismatch as a cache miss, deleting the entry so the loader re-downloads instead of loading broken bytes. Entries written before this change store an empty checksum and stay readable without forcing a re-download. Adds tests for checksum computation against known SHA-256 vectors and for legacy and mismatched checksum verification.
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.
Store real version and checksum for cached WASM parsers
Problem
Cached tree-sitter parser entries were written with a hardcoded
version: "1.0.0"and an emptychecksum(the two TODOs inloader.ts). The cache metadata carried no real information, and there was no way to detect corrupted or tampered parser bytes on disk.Changes
src/features/editor/lib/wasm-parser/checksum.ts: SHA-256 over the WASM bytes via WebCrypto (crypto.subtle.digest), plus a verification helper.createCacheEntrybuilder) store:getLanguageExtensionById, falling back to"unknown".Testing
src/features/editor/tests/wasm-parser-checksum.test.tscovers known SHA-256 vectors ("abc" and empty input), match/mismatch verification, and the legacy empty-checksum case.bun checkstill reports 5 pre-existingcargo fmtdiffs that also appear on a clean checkout ofmain(stable rustfmt cannot apply the nightly-only options); nothing new from this change.I agree to the Contributor License and Feedback Agreement.