From: Dmitry Volyntsev Date: Tue, 23 Apr 2024 00:52:06 +0000 (-0700) Subject: Zlib: fixed inflate(). X-Git-Tag: 0.8.5~40 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=af731e0d6721228869bf62a116473c1497356e51;p=njs.git 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. --- diff --git a/external/njs_zlib_module.c b/external/njs_zlib_module.c index 3f2e23fe..9e35c2e8 100644 --- a/external/njs_zlib_module.c +++ b/external/njs_zlib_module.c @@ -463,7 +463,7 @@ njs_zlib_ext_inflate(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, 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 --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 1740a4ca..ff34c940 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -22351,6 +22351,13 @@ static njs_unit_test_t njs_zlib_test[] = ".map(v => zlib.deflateSync(v).toString('base64'))"), 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')])"