Skip to content

Add a way to enable content checksums - #177

Open
vignesh2027 wants to merge 1 commit into
DataDog:1.xfrom
vignesh2027:checksum-option
Open

vignesh2027 wants to merge 1 commit into
DataDog:1.xfrom
vignesh2027:checksum-option

Conversation

@vignesh2027

Copy link
Copy Markdown

Fixes #43.

Frames produced by this package never include the optional content checksum, so compressing an empty slice gives 9 bytes where the zstd command line tool gives 13. This adds a way to turn it on.

New API: CompressLevelChecksum(dst, src, level) on the package and on Ctx, and Writer.SetChecksum(bool) for the streaming API. Existing functions behave exactly as before, so nothing changes unless a caller opts in. Adding the method to Ctx does break anyone who implements that interface outside the package, the same as DecompressInto did in #151. If you would rather avoid that, I can move it to a separate optional interface instead. Decompress and the stream Reader already verify the checksum when a frame carries one.

The Ctx variant goes through ZSTD_compress2 after a parameter reset, because ZSTD_compressCCtx ignores advanced parameters. A test checks that a later CompressLevel call on the same context still produces a frame without a checksum.

Tests cover the 13 byte empty frame from the issue, round trips, the 4 byte size difference, corruption of the checksum being rejected by Decompress, Ctx and the stream Reader, and toggling the setting back off. Full suite passes with -race.

Frames written by this package never carried the optional 32 bit content
checksum, unlike the zstd command line tool. Add CompressLevelChecksum on the
package and on Ctx, and Writer.SetChecksum for the streaming API. Decompression
already verifies the checksum when a frame has one.

The Ctx variant sets its parameters through ZSTD_compress2 after a parameter
reset, so the setting does not leak into later CompressLevel calls on the same
context.

Fixes DataDog#43
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.

Add a way to enable checksums

1 participant