Skip further compression and writes after LZ4 close failures

Started by Chao Liabout 1 month ago1 messageshackers
Jump to latest
#1Chao Li
li.evan.chao@gmail.com

Hi,

While working on patch [1]/messages/by-id/5962B878-C43D-4EBC-9E95-1F945CE5E586@gmail.com, I spotted that LZ4Stream_close() doesn’t handle failures cleanly.

If fwrite() fails, it sets the success flag to false, but still proceeds to call LZ4F_compressEnd(). And if LZ4F_compressEnd() fails, it still calls fwrite() without advancing state->bufdata. I don’t think this would lead to an incorrect result, as the success flag remains false, but further compression and write attempts after a failure are unnecessary and may produce additional error messages.

Looking at zstd, gzip, and custom-format compression, their close paths don’t have the same issue.

Attached is a simple cleanup patch for LZ4Stream_close(). I don’t think it needs to be back-patched.

[1]: /messages/by-id/5962B878-C43D-4EBC-9E95-1F945CE5E586@gmail.com

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachments:

t254148_1
v1-0001-Avoid-further-compression-and-writes-after-LZ4-cl.patchapplication/octet-stream; name=v1-0001-Avoid-further-compression-and-writes-after-LZ4-cl.patch; x-unix-mode=0644Download+21-16