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

[fix] Add missing bounds checks during compression #2709

Merged
merged 1 commit into from
Jun 14, 2021

Conversation

terrelln
Copy link
Contributor

  • The block splitter missed a bounds check, so when the buffer is too small it
    passes an erroneously large size to ZSTD_entropyCompressSeqStore(), which
    can then write the compressed data past the end of the buffer. This is a new
    regression in v1.5.0 when the block splitter is enabled. It is either enabled
    explicitly, or implicitly when using the optimal parser and ZSTD_compress2()
    or ZSTD_compressStream*().
  • HUF_writeCTable_wksp() omits a bounds check when calling
    HUF_compressWeights(). If it is called with dstCapacity == 0 it will pass
    an erroneously large size to HUF_compressWeights(), which can then write
    past the end of the buffer. This bug has been present for ages. However, I
    believe that zstd cannot trigger the bug, because it never calls
    HUF_compress*() with dstCapacity == 0 because of this check.

Credit to: Oss-Fuzz

* The block splitter missed a bounds check, so when the buffer is too small it
  passes an erroneously large size to `ZSTD_entropyCompressSeqStore()`, which
  can then write the compressed data past the end of the buffer. This is a new
  regression in v1.5.0 when the block splitter is enabled. It is either enabled
  explicitly, or implicitly when using the optimal parser and `ZSTD_compress2()`
  or `ZSTD_compressStream*()`.
* `HUF_writeCTable_wksp()` omits a bounds check when calling
  `HUF_compressWeights()`. If it is called with `dstCapacity == 0` it will pass
  an erroneously large size to `HUF_compressWeights()`, which can then write
  past the end of the buffer. This bug has been present for ages. However, I
  believe that zstd cannot trigger the bug, because it never calls
  `HUF_compress*()` with `dstCapacity == 0` because of [this check][1].

Credit to: Oss-Fuzz

[1]: https://github.com/facebook/zstd/blob/89127e5ee2f3c1e141668fa6d4ee91245f05d132/lib/compress/zstd_compress_literals.c#L100
Copy link
Contributor

@senhuang42 senhuang42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

@terrelln terrelln merged commit 6917c4e into facebook:dev Jun 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants