-
Notifications
You must be signed in to change notification settings - Fork 2
Support dictionary-compressed virtual chunk locations #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2c05be8
vendor fzstd with dictionary decompression support
Shane98c fa4234b
decode dictionary-compressed virtual chunk locations
Shane98c aca59a2
regenerate flatbuffer code for upstream SnapshotInfo change
Shane98c 562c950
fix 32-bit shift overflow in zstd frame size guard
Shane98c edb4d53
reject concatenated zstd frames in location size guard
Shane98c 82b7814
note schema vs Rust-reference mismatch for compression_algorithm 0
Shane98c e426b39
re-vendor fzstd from updated PR#18 branch (aliasing fix now upstream)
Shane98c d8685c1
decode compressed virtual chunk locations lazily
Shane98c e6a01cb
bound per-block output in location size guard
Shane98c c016796
re-vendor fzstd from updated branch (history-window fix now upstream)
Shane98c File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| dist | ||
| node_modules | ||
| tests/data | ||
|
|
||
| # Vendored third-party source — keep byte-identical to upstream | ||
| src/vendor |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2020 Arjun Barrett | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # Vendored `fzstd` | ||
|
|
||
| This directory contains a vendored copy of [`fzstd`](https://github.com/101arrowz/fzstd) | ||
| (MIT, © 2020 Arjun Barrett) used for zstd decompression — both the outer | ||
| metadata-file decompression and the dictionary-compressed virtual chunk | ||
| locations in manifests. | ||
|
|
||
| ## Why it's vendored (not an npm dependency) | ||
|
|
||
| - **Released `fzstd` (0.1.1) has no dictionary support.** Its `decompress()` | ||
| takes no dictionary argument, and icechunk's `compressed_location` fields are | ||
| zstd frames compressed against a per-manifest dictionary — undecodable | ||
| without it. Dictionary support exists only in the unmerged | ||
| [fzstd#18](https://github.com/101arrowz/fzstd/pull/18). | ||
| - **The PR branch can't be cleanly `npm install`ed** — its `package.json` | ||
| `main`/`module` point at build outputs that aren't committed, and there's no | ||
| `prepare` hook, so a git/`github:` install resolves to missing files. | ||
| - **`zstdify` (the other dictionary-capable JS zstd lib) silently corrupts | ||
| data** — it returned wrong bytes (same length, no error) for ~32% of real | ||
| icechunk metadata fixtures, at both 1.4.0 and `main` (the PR#3 "fix" does not | ||
| address it). `fzstd` is byte-exact vs the reference `zstd` CLI on all of them. | ||
|
|
||
| So we vendor the dictionary-capable source and decompress with it everywhere. | ||
|
|
||
| ## Upstream source | ||
|
|
||
| | | | | ||
| |---|---| | ||
| | Repo | `101arrowz/fzstd` | | ||
| | Branch | `handlerug:push-qxkytkvukoqs` (= the head of fzstd#18) | | ||
| | Commit | `c039e52` "Support loading a dictionary for decompression" | | ||
| | File | `src/index.ts` → `index.ts` here (with a header prepended) | | ||
| | License | `LICENSE` (copied verbatim) | | ||
|
|
||
| `index.ts` is `@ts-nocheck`'d and excluded from Prettier (`.prettierignore`) to | ||
| stay byte-identical to upstream apart from the documented patch below. | ||
|
|
||
| ## Local modifications | ||
|
|
||
| There is **one** deliberate change from upstream, marked in `index.ts` with a | ||
| `LOCAL PATCH (icechunk-js)` comment (and summarized in the file header): | ||
|
|
||
| - **Dictionary/output-buffer aliasing fix** — in `decompress()`, the | ||
| no-output-buffer fast path is guarded with `!dic`: | ||
| `if (!dic && st.w.length == st.u)`. When a dictionary is loaded, `rdic()` | ||
| replaces `st.w` with the dictionary history; reusing it as the output buffer | ||
| aliases back-reference reads with output writes and silently corrupts the | ||
| result whenever the dictionary-content length equals the decompressed size. | ||
| - Submitted upstream: **https://github.com/handlerug/fzstd/pull/1** | ||
| (against the fzstd#18 branch). When it merges and a release is published, | ||
| drop this patch on the next re-vendor. | ||
| - Regression coverage: `tests/format/flatbuffers/manifest-dictionary.test.ts` | ||
| ("decodes a frame whose output aliases the dictionary buffer"). | ||
|
|
||
| > Note: the size-bound (`MAX_DECOMPRESSED_LOCATION_SIZE`) and UTF-8 strictness | ||
| > guards are **not** here — they live in the consumer | ||
| > (`src/format/flatbuffers/manifest-parser.ts`), since bounding untrusted input | ||
| > is the caller's job, not the decoder's. | ||
|
|
||
| ## Re-vendoring (updating the copy) | ||
|
|
||
| ```sh | ||
| # Fetch the upstream source for the pinned branch/commit: | ||
| gh api "repos/handlerug/fzstd/contents/src/index.ts?ref=push-qxkytkvukoqs" \ | ||
| --jq '.content' | base64 -d > /tmp/fzstd-index.ts | ||
| ``` | ||
|
|
||
| Then: | ||
| 1. Re-prepend the provenance header (top of the current `index.ts`). | ||
| 2. **Re-apply the local patch** — add `!dic &&` to the fast-path guard in | ||
| `decompress()` (search for `st.w.length == st.u`). | ||
| 3. Re-run the suite: `npm test` (the aliasing + dictionary tests must pass). | ||
|
|
||
| ## When this can be deleted | ||
|
|
||
| Once fzstd#18 **and** the aliasing fix land upstream and a release is published | ||
| to npm: delete this directory, add `fzstd@<version>` to `dependencies`, and | ||
| repoint the four imports (`src/reader/session.ts`, | ||
| `src/format/flatbuffers/{repo,manifest}-parser.ts`, and the two parser tests). | ||
|
|
||
| ## Related | ||
|
|
||
| - Consumer: `src/format/flatbuffers/manifest-parser.ts` (dictionary decode, | ||
| decode priority matching the Rust `ref_to_payload`, size/UTF-8 guards). | ||
| - Test fixtures: `tests/fixtures/dictionary/` (generated with the `zstd` CLI; | ||
| generation commands documented in the test file headers). |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In JavaScript, bitwise operators (like
<<and>>) operate on 32-bit signed integers. If the window descriptorwdhas a large exponent (e.g.,wd >> 3 >= 21),10 + (wd >> 3)will be >= 31, causing1 << (10 + (wd >> 3))to overflow or wrap around to a negative or incorrect value. Similarly,base >> 3will overflow ifbaseis >= 2^31.To prevent this and ensure correct handling of large window sizes (especially when validating untrusted input), use standard arithmetic exponentiation (
2 ** ...) and division (/ 8) instead of bitwise shifts.