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

Clarify dstCapacity requirements #3531

Merged
merged 1 commit into from
Mar 9, 2023

Conversation

terrelln
Copy link
Contributor

@terrelln terrelln commented Mar 7, 2023

Clarify dstCapacity requirements for single-pass functions.

Fixes #3524.

Clarify `dstCapacity` requirements for single-pass functions.

Fixes facebook#3524.
@@ -578,7 +579,8 @@ ZSTDLIB_API size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset);
* Should cctx hold data from a previously unfinished frame, everything about it is forgotten.
* - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_set*()
* - The function is always blocking, returns when compression is completed.
* Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`.
* NOTE: Providing `dstCapacity >= ZSTD_compressBound(srcSize)` guarantees that zstd will have
* enough space to successfully compress the data, though it is possible it fails for other reasons.
Copy link
Contributor

Choose a reason for hiding this comment

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

though it is possible it fails for other reasons

What other reasons do you have in mind ?
Memory allocation failures ?
Providing dstCapacity >= ZSTD_compressBound(srcSize) should be enough to avoid #3524.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean ZSTD_compress2() can let you specify a lot of options. E.g. compression could fail to allocate a thread. We could run out of memory.

I only mentioned this in ZSTD_compress2(), and skipped it in ZSTD_compress(), but I just mean that you still have to check the error code.

@terrelln terrelln merged commit c40c737 into facebook:dev Mar 9, 2023
@terrelln terrelln deleted the 2023-03-07-issue-3524 branch March 9, 2023 18:20
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.

zstd 1.5.4 compression error less than or equal to 4 bytes src by the ZSTD_compress function
3 participants