crypto: deflate - fix decompression window size
PATCH 1/1 crypto: deflate - fix decompression window size
deflate_decompress() initializes the inflate stream with windowBits set to -DEFLATE_DEF_WINBITS (11 bits, 2KB window). Valid raw DEFLATE streams allow window sizes up to MAX_WBITS (15 bits, 32KB). Using a smaller window than the one used during compression causes decompression to fail for externally generated data. This might occur if data is compressed with a compressor that is not deflate-generic (i.e. this implementation).
Use -MAX_WBITS when calling zlib_inflateInit2() to accept all valid raw DEFLATE streams. The inflate workspace allocated in deflate_alloc_stream() is already sized using zlib_inflate_workspacesize(), which accounts for the maximum window size, so no allocation change is needed.
--- crypto/deflate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/deflate.c +1 -1
@@ -203,7 +203,7 @@ static int deflate_decompress(struct acomp_req *req) s =crypto_acomp_lock_stream_bh (&deflate_streams); ds = s->ctx; - err =zlib_inflateInit2 (&ds->stream, -DEFLATE_DEF_WINBITS ); + err =zlib_inflateInit2 (&ds->stream, -MAX_WBITS );if (err !=Z_OK ) { err = -EINVAL ; goto out;
Signature · 1 line
2.53.0
Herbert Xu
maintainerQuoted 8 lines · Giovanni Cabiddu
deflate_decompress()initializes the inflate stream with windowBits set to -DEFLATE_DEF_WINBITS (11 bits, 2KB window). Valid raw DEFLATE streams allow window sizes up toMAX_WBITS(15 bits, 32KB). Using a smaller window than the one used during compression causes decompression to fail for externally generated data. This might occur if data is compressed with a compressor that is not deflate-generic (i.e. this implementation).
Quoted 6 lines
Use -MAX_WBITS when calling
zlib_inflateInit2()to accept all valid raw DEFLATE streams. The inflate workspace allocated indeflate_alloc_stream()is already sized usingzlib_inflate_workspacesize(), which accounts for the maximum window size, so no allocation change is needed.Fixes 08cabc7d3c86 ("crypto: deflate - Convert to acomp")
That commit doesn't touch this at all. I think you meant
commit 62a465c25e99b9a98259a6b7f5bb759f5296d501
Author: Herbert Xu <[email protected]> Date: Wed Aug 30 17:56:25 2023 +0800
crypto: deflate - Remove zlib-deflate
But this simply restored the status quo prior to
commit a368f43d6e3a001e684e9191a27df384fbff12f5
Author: Giovanni Cabiddu <[email protected]> Date: Fri Apr 21 21:54:30 2017 +0100
crypto: scomp - add support for deflate rfc1950 (zlib)
So the commit message needs to be rewritten to clearly state why this is needed for the "deflate" algorithm.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
Quoted 26 lines · Herbert Xu
Quoted 8 lines · Giovanni Cabiddu
deflate_decompress()initializes the inflate stream with windowBits set to -DEFLATE_DEF_WINBITS (11 bits, 2KB window). Valid raw DEFLATE streams allow window sizes up toMAX_WBITS(15 bits, 32KB). Using a smaller window than the one used during compression causes decompression to fail for externally generated data. This might occur if data is compressed with a compressor that is not deflate-generic (i.e. this implementation).Quoted 6 lines
Use -MAX_WBITS when calling
zlib_inflateInit2()to accept all valid raw DEFLATE streams. The inflate workspace allocated indeflate_alloc_stream()is already sized usingzlib_inflate_workspacesize(), which accounts for the maximum window size, so no allocation change is needed.Fixes 08cabc7d3c86 ("crypto: deflate - Convert to acomp")That commit doesn't touch this at all. I think you meant
commit
62a465c25e99b9a98259a6b7f5bb759f5296d501Author: Herbert Xu <[email protected]> Date: Wed Aug 30 17:56:25 2023 +0800crypto: deflate - Remove zlib-deflate
But this simply restored the status quo prior to
Quoted 8 lines
commit
a368f43d6e3a001e684e9191a27df384fbff12f5Author: Giovanni Cabiddu <[email protected]> Date: Fri Apr 21 21:54:30 2017 +0100crypto: scomp - add support for deflate rfc1950 (zlib)
So the commit message needs to be rewritten to clearly state why this is needed for the "deflate" algorithm.
My bad. Sorry about that.
I think the Fixes tag should report either the commit that introduced deflate-scomp
commit f6ded09de8bdaa405ab90b1b6c4166e69a23664d
Author: Giovanni Cabiddu <[email protected]>
Date: Fri Oct 21 13:19:53 2016 +0100
crypto: acomp - add support for deflate via scomp
OR the one that introduced deflate...
commit 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (tag: v2.6.12-rc2)
Author: Linus Torvalds <[email protected]>
Date: Sat Apr 16 15:20:36 2005 -0700
Linux-2.6.12-rc2What do you think?
The motivation for this change is that data compressed with a history window larger than 2 KB (for example, by QAT or IAA) might not be decompressed by deflate-generic, which currently initializes the inflate stream with a 2 KB window.
I'll rework the commit message to make this explicit and resubmit.
Regards,
Signature · 1 line
Giovanni