Skip to content

compressor/zstd: validate decompression and fix DStream leak - #69584

Closed
lumir-sliva wants to merge 1 commit into
ceph:mainfrom
lumir-sliva:zstd-decompress-error-handling
Closed

lumir-sliva wants to merge 1 commit into
ceph:mainfrom
lumir-sliva:zstd-decompress-error-handling

Conversation

@lumir-sliva

Copy link
Copy Markdown
Contributor

ZstdCompressor::decompress() ignores the return of ZSTD_decompressStream() and assumes every input chunk is fully consumed. So a corrupt, truncated, or inconsistent zstd frame returns success (0) with silently truncated or garbage output, and callers (BlueStore, RGW, OSD message decompression) can't tell good data from bad. Same class of silent-corruption problem as the 2020 lz4 bug. The compress() path right above it already checks every libzstd return; decompress() just never got the same treatment. Reported by a user auditing the zstd path before turning it on in production (#77334).

What changed in decompress():

  • check ZSTD_createDStream() for NULL (-ENOMEM) and ZSTD_initDStream() for an error, matching compress()
  • check the ZSTD_decompressStream() return with ZSTD_isError()
  • require zstd to consume the whole input chunk. If it stops early the output buffer filled up, which means the decoded-length prefix understated the real size: a corrupt or inconsistent frame
  • after the loop, require the frame to have ended and to have produced exactly the byte count the length prefix promised
  • free the DStream on the mid-loop early-return that used to leak it, and return -EINVAL/-ENOMEM instead of a bare -1

compress() also gets a guard against a source bigger than the uint32_t length prefix can hold, which would otherwise truncate silently and make the data impossible to decompress.

New unit test compresses a payload and feeds truncated, under-sized-prefix, over-sized-prefix, and garbage variants to decompress(), each has to fail with a negative code now instead of returning 0.

unittest_compression passes all 92 tests, including every zstd round-trip and the new corruption case.

Tracker: https://tracker.ceph.com/issues/77334

Checklist

  • Tracker (select at least one)
    • References tracker ticket
  • Component impact
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • No doc update is appropriate
  • Tests (select at least one)
    • Includes unit test(s)

ZstdCompressor::decompress() ignored the return value of
ZSTD_decompressStream() and assumed every input chunk was fully
consumed. A corrupt, truncated, or inconsistent frame therefore
returned success (0) with silently truncated or garbage output, and
callers (BlueStore, RGW, OSD message decompression) had no way to tell
good data from bad. The compress() path in the same file already checks
every libzstd return; decompress() never received the same treatment.

Make decompress() reject bad input:

- check ZSTD_createDStream() for NULL (return -ENOMEM) and
  ZSTD_initDStream() for an error code, matching compress().
- check the ZSTD_decompressStream() return for ZSTD_isError().
- require zstd to consume the whole input chunk; if it stops early the
  output buffer filled, meaning the decoded-length prefix understated
  the real size (a corrupt or inconsistent frame).
- after the loop, require the frame to have ended (last return == 0) and
  to have produced exactly the number of bytes promised by the prefix.
- free the DStream on the mid-loop early-return path that previously
  leaked it, and return -EINVAL/-ENOMEM instead of the bare -1.

Also guard compress() against a source larger than the uint32_t length
prefix can represent, which would otherwise truncate silently and make
the data impossible to decompress.

Add a unit test that compresses a payload and then feeds truncated,
under-/over-sized-prefix, and garbage variants to decompress(), each of
which must now fail with a negative error code.

Tracker: https://tracker.ceph.com/issues/77334
Signed-off-by: Slíva, Lumír <[email protected]>
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

16 similar comments
@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@ceph-jenkins

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. Since you, the author, are not a member of the Ceph GitHub Org yet, our CI will not automatically run. Any member of the Ceph Org may comment "ok - to - test" (without the dashes) to allow the Jenkins jobs to run.

@github-actions github-actions Bot added the tests label Jun 18, 2026
@lumir-sliva

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #69733, which fixes #77334 more completely (RAII on both contexts, hardened compress path, more tests) and is from the reporter's own team. Sorry for the dupe.

@lumir-sliva lumir-sliva closed this Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants