summaryrefslogtreecommitdiff
path: root/libbcachefs/compress.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbcachefs/compress.c')
-rw-r--r--libbcachefs/compress.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/libbcachefs/compress.c b/libbcachefs/compress.c
index aebf46bb..f63651d2 100644
--- a/libbcachefs/compress.c
+++ b/libbcachefs/compress.c
@@ -336,8 +336,19 @@ static int attempt_compress(struct bch_fs *c,
ZSTD_CCtx *ctx = ZSTD_initCCtx(workspace,
ZSTD_CCtxWorkspaceBound(c->zstd_params.cParams));
+ /*
+ * ZSTD requires that when we decompress we pass in the exact
+ * compressed size - rounding it up to the nearest sector
+ * doesn't work, so we use the first 4 bytes of the buffer for
+ * that.
+ *
+ * Additionally, the ZSTD code seems to have a bug where it will
+ * write just past the end of the buffer - so subtract a fudge
+ * factor (7 bytes) from the dst buffer size to account for
+ * that.
+ */
size_t len = ZSTD_compressCCtx(ctx,
- dst + 4, dst_len - 4,
+ dst + 4, dst_len - 4 - 7,
src, src_len,
c->zstd_params);
if (ZSTD_isError(len))