Skip to content

Commit

Permalink
make zdb_decompress_block check its decompression reliably
Browse files Browse the repository at this point in the history
This function decompresses to two buffers and then compares them to check whether the (opaque) decompression process filled the whole buffer. Previously it began with lbuf uninitialized and lbuf2 filled with pseudorandom data. This neither guarantees that any bytes not written by the compressor would be different, nor seems incredibly sound otherwise!

After these changes, instead of filling one buffer with generated pseudorandom data we overwrite each buffer with completely different data. This should remove the possibility of low-probability failures, as well as make the process simpler and cheaper.

Signed-off-by: Kent Ross <[email protected]>
  • Loading branch information
mumbleskates committed Jan 2, 2024
1 parent b9d9845 commit c0502ff
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -8031,11 +8031,14 @@ zdb_decompress_block(abd_t *pabd, void *buf, void *lbuf, uint64_t lsize,
}

/*
* We randomize lbuf2, and decompress to both
* lbuf and lbuf2. This way, we will know if
* decompression fill exactly to lsize.
* We set lbuf to all zeros and lbuf2 to all
* ones, then decompress to both buffers and
* compare their contents. This way we can
* know if decompression filled exactly to
* lsize or if it left some bytes unwritten.
*/
VERIFY0(random_get_pseudo_bytes(lbuf2, lsize));
memset(lbuf, 0x00, lsize);
memset(lbuf2, 0xff, lsize);

if (zio_decompress_data(*cfuncp, pabd,
lbuf, psize, lsize, NULL) == 0 &&
Expand Down

0 comments on commit c0502ff

Please sign in to comment.