From: Chao Yu Date: Fri, 8 May 2020 01:16:03 +0000 (+0800) Subject: f2fs: compress: fix zstd data corruption X-Git-Tag: v5.7.6~290 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=88868e552b1d677f026202efe8cb3f701121b0a3;p=users%2Fdwmw2%2Flinux.git f2fs: compress: fix zstd data corruption [ Upstream commit 1454c978efbb57b052670d50023f48c759d704ce ] During zstd compression, ZSTD_endStream() may return non-zero value because distination buffer is full, but there is still compressed data remained in intermediate buffer, it means that zstd algorithm can not save at last one block space, let's just writeback raw data instead of compressed one, this can fix data corruption when decompressing incomplete stored compression data. Fixes: 50cfa66f0de0 ("f2fs: compress: support zstd compress algorithm") Signed-off-by: Daeho Jeong Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index c05801758a358..a5b2e72174bb1 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -369,6 +369,13 @@ static int zstd_compress_pages(struct compress_ctx *cc) return -EIO; } + /* + * there is compressed data remained in intermediate buffer due to + * no more space in cbuf.cdata + */ + if (ret) + return -EAGAIN; + cc->clen = outbuf.pos; return 0; }