Skip to content
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

zstd: Fix corrupted output in "best" #876

Merged
merged 3 commits into from
Oct 22, 2023
Merged

Conversation

klauspost
Copy link
Owner

@klauspost klauspost commented Oct 22, 2023

Regression from #784 and followup #793

Fixes #875

A 0 offset backreference was possible when "improve" was successful twice in a row in the "skipBeginning" part, only finding 2 (previously unmatched) length 4 matches, but where start offset decreased by 2 in both cases.

This would result in output where the end offset would equal to the next 's', thereby doing a self-reference.

Add a general check in "improve" and just reject these. Will also guard against similar issues in the future.

This also hints at some potentially suboptimal hash indexing - but I will take that improvement separately.

Fuzz test set updated.

Regression from #784 and followup #793

Fixes #875

A 0 offset backreference was possible when "improve" was successful twice in a row in the "skipBeginning" part, only finding 2 (previously unmatches) length 4 matches, but where start offset decreased by 2 in both cases.

This would result in output where the end offset would equal to the next 's', thereby doing a self-reference.

Add a general check in "improve" and just reject these. Will also guard against similar issues in the future.

This also hints at some potentially suboptimal hash indexing - but I will take that improvement separately.

Fuzz test set updated.
zstd/enc_best.go Show resolved Hide resolved
zstd/enc_best.go Outdated Show resolved Hide resolved
@klauspost klauspost merged commit 8eb6542 into master Oct 22, 2023
18 checks passed
@klauspost klauspost deleted the zstd-fix-best-corruption branch October 22, 2023 15:44
kodiakhq bot referenced this pull request in cloudquery/filetypes Nov 1, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/klauspost/compress](https://togithub.com/klauspost/compress) | indirect | patch | `v1.17.0` -> `v1.17.2` |

---

### Release Notes

<details>
<summary>klauspost/compress (github.com/klauspost/compress)</summary>

### [`v1.17.2`](https://togithub.com/klauspost/compress/releases/tag/v1.17.2)

[Compare Source](https://togithub.com/klauspost/compress/compare/v1.17.1...v1.17.2)

#### What's Changed

-   zstd: Fix corrupted output in "best" by [@&#8203;klauspost](https://togithub.com/klauspost) in [https://github.com/klauspost/compress/pull/876](https://togithub.com/klauspost/compress/pull/876)

**Full Changelog**: klauspost/compress@v1.17.1...v1.17.2

### [`v1.17.1`](https://togithub.com/klauspost/compress/releases/tag/v1.17.1)

[Compare Source](https://togithub.com/klauspost/compress/compare/v1.17.0...v1.17.1)

#### What's Changed

-   s2: Fix S2 "best" dictionary wrong encoding by [@&#8203;klauspost](https://togithub.com/klauspost) in [https://github.com/klauspost/compress/pull/871](https://togithub.com/klauspost/compress/pull/871)
-   flate: Reduce allocations in decompressor and minor code improvements by [@&#8203;fakefloordiv](https://togithub.com/fakefloordiv) in [https://github.com/klauspost/compress/pull/869](https://togithub.com/klauspost/compress/pull/869)
-   s2: Fix EstimateBlockSize on 6&7 length input by [@&#8203;klauspost](https://togithub.com/klauspost) in [https://github.com/klauspost/compress/pull/867](https://togithub.com/klauspost/compress/pull/867)
-   tests: Fuzzing Coverage Expansion by [@&#8203;viktoriia-lsg](https://togithub.com/viktoriia-lsg) in [https://github.com/klauspost/compress/pull/866](https://togithub.com/klauspost/compress/pull/866)
-   tests: Set FSE decompress fuzzer max limit by [@&#8203;klauspost](https://togithub.com/klauspost) in [https://github.com/klauspost/compress/pull/868](https://togithub.com/klauspost/compress/pull/868)
-   tests: Fuzzing Coverage Expansion ([#&#8203;2](https://togithub.com/klauspost/compress/issues/2)) by [@&#8203;viktoriia-lsg](https://togithub.com/viktoriia-lsg) in [https://github.com/klauspost/compress/pull/870](https://togithub.com/klauspost/compress/pull/870)

#### New Contributors

-   [@&#8203;viktoriia-lsg](https://togithub.com/viktoriia-lsg) made their first contribution in [https://github.com/klauspost/compress/pull/866](https://togithub.com/klauspost/compress/pull/866)
-   [@&#8203;fakefloordiv](https://togithub.com/fakefloordiv) made their first contribution in [https://github.com/klauspost/compress/pull/869](https://togithub.com/klauspost/compress/pull/869)

**Full Changelog**: klauspost/compress@v1.17.0...v1.17.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am on the first day of the month" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://togithub.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMDkuNCIsInVwZGF0ZWRJblZlciI6IjM2LjEwOS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

zstd: Data corruption on SpeedBestCompression level
2 participants