details: https://hg.nginx.org/njs/rev/d640adf691a7 branches: changeset: 2319:d640adf691a7 user: Dmitry Volyntsev <xei...@nginx.com> date: Mon Apr 22 17:52:06 2024 -0700 description: Zlib: fixed inflate().
Previously, the function might fail to return the last part of the compressed content. This problem is more visible when output size > 1024 or when chunkSize < the content size. diffstat: external/njs_zlib_module.c | 2 +- src/test/njs_unit_test.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletions(-) diffs (29 lines): diff -r be271e8d0b3b -r d640adf691a7 external/njs_zlib_module.c --- a/external/njs_zlib_module.c Mon Apr 22 17:51:45 2024 -0700 +++ b/external/njs_zlib_module.c Mon Apr 22 17:52:06 2024 -0700 @@ -463,7 +463,7 @@ njs_zlib_ext_inflate(njs_vm_t *vm, njs_v njs_chb_init(&chain, njs_vm_memory_pool(vm)); - while (stream.avail_in > 0) { + while (rc != Z_STREAM_END) { stream.next_out = njs_chb_reserve(&chain, chunk_size); if (njs_slow_path(stream.next_out == NULL)) { njs_vm_memory_error(vm); diff -r be271e8d0b3b -r d640adf691a7 src/test/njs_unit_test.c --- a/src/test/njs_unit_test.c Mon Apr 22 17:51:45 2024 -0700 +++ b/src/test/njs_unit_test.c Mon Apr 22 17:52:06 2024 -0700 @@ -22352,6 +22352,13 @@ static njs_unit_test_t njs_zlib_test[] njs_str("eJwLd/R2BAAC+gEl,eJw7t/HcpnObAQ/sBIE=") }, { njs_str("const zlib = require('zlib');" + "const buf = 'αβγ'.repeat(56);" + "const enc = zlib.deflateRawSync(buf, {chunkSize:64}).toString('base64');" + "const dec = zlib.inflateRawSync(Buffer.from(enc, 'base64')).toString();" + "buf == dec"), + njs_str("true") }, + + { njs_str("const zlib = require('zlib');" "['WAKA'.repeat(1024), 'αβγ'.repeat(1024)]" ".map(v => [v, zlib.deflateRawSync(v).toString('base64')])" ".every(pair => pair[0] == zlib.inflateRawSync(Buffer.from(pair[1], 'base64')).toString())"), _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx-devel