aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorRob Norris <[email protected]>2024-07-23 11:43:18 +1000
committerTony Hutter <[email protected]>2024-08-22 16:22:24 -0700
commitcb36f4f3529473d977189010f41b9a98c644d2d3 (patch)
tree54f915f95c00e1df1ef5954d5cff3f46df313ae6 /cmd
parenta537d90734a16d63c79080cfd2d710745d7c02fd (diff)
zstream recompress: fix zero recompressed buffer and output
If compression happend, any garbage past the compress size was not zeroed out. If compression didn't happen, then the payload size was still set to the rounded-up return from zio_compress_data(), which is dependent on the input, which is not necessarily the logical size. So that's all fixed too, mostly from stealing the math from zio.c. Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. Signed-off-by: Rob Norris <[email protected]>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/zstream/zstream_recompress.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/cmd/zstream/zstream_recompress.c b/cmd/zstream/zstream_recompress.c
index 32ef6fa54..ae2c56320 100644
--- a/cmd/zstream/zstream_recompress.c
+++ b/cmd/zstream/zstream_recompress.c
@@ -287,24 +287,26 @@ zstream_do_recompress(int argc, char *argv[])
dbuf, drrw->drr_logical_size);
abd_t *pabd =
abd_get_from_buf_struct(&abd, buf, bufsz);
- payload_size = P2ROUNDUP(zio_compress_data(
- ctype, &dabd, &pabd,
- drrw->drr_logical_size, level),
- SPA_MINBLOCKSIZE);
- if (payload_size != drrw->drr_logical_size) {
- drrw->drr_compressiontype = ctype;
- drrw->drr_compressed_size =
- payload_size;
- } else {
+ size_t csize = zio_compress_data(ctype, &dabd,
+ &pabd, drrw->drr_logical_size, level);
+ size_t rounded =
+ P2ROUNDUP(csize, SPA_MINBLOCKSIZE);
+ if (rounded >= drrw->drr_logical_size) {
memcpy(buf, dbuf, payload_size);
drrw->drr_compressiontype = 0;
drrw->drr_compressed_size = 0;
+ } else {
+ abd_zero_off(pabd, csize,
+ rounded - csize);
+ drrw->drr_compressiontype = ctype;
+ drrw->drr_compressed_size =
+ payload_size = rounded;
}
abd_free(&abd);
abd_free(&dabd);
free(dbuf);
} else {
- drrw->drr_compressiontype = ctype;
+ drrw->drr_compressiontype = 0;
drrw->drr_compressed_size = 0;
}
break;