From c5459c92a82c33611ab69637f75c47d4b0045a6f Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Wed, 17 Apr 2024 11:52:58 +0200 Subject: add upstream patch for zlib-ng --- github704.patch | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ njs.spec | 7 ++++++ 2 files changed, 83 insertions(+) create mode 100644 github704.patch diff --git a/github704.patch b/github704.patch new file mode 100644 index 0000000..22e894a --- /dev/null +++ b/github704.patch @@ -0,0 +1,76 @@ +# HG changeset patch +# User Dmitry Volyntsev +# Date 1713338720 25200 +# Wed Apr 17 00:25:20 2024 -0700 +# Node ID ca18b6292d6eea0bb58f5e7b08a7249d04629a8a +# Parent 40c980ca34563c056e871d5585d1aedd8f4d0890 +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 is > +1024 or when chunkSize < the content size. + +diff --git a/external/njs_zlib_module.c b/external/njs_zlib_module.c +--- 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_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 --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c +--- a/src/test/njs_unit_test.c ++++ b/src/test/njs_unit_test.c +@@ -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())"), +# HG changeset patch +# User Dmitry Volyntsev +# Date 1713338872 25200 +# Wed Apr 17 00:27:52 2024 -0700 +# Node ID 2b6b25100aef6cbf8c2ab0bc2bd4d60942e41a45 +# Parent ca18b6292d6eea0bb58f5e7b08a7249d04629a8a +Zlib: improved tests with zlib-ng. + +This fixes #704 issue on Github. + +diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c +--- a/src/test/njs_unit_test.c ++++ b/src/test/njs_unit_test.c +@@ -22319,14 +22319,15 @@ static njs_unit_test_t njs_zlib_test[] + njs_str("WAKA,αβγ") }, + + { njs_str("const zlib = require('zlib');" +- "['WAKA', 'αβγ']" +- ".map(v => zlib.deflateRawSync(v).toString('base64'))"), +- njs_str("C3f0dgQA,O7fx3KZzmwE=") }, ++ "const enc = ['WAKA', 'αβγ'].map(v => zlib.deflateRawSync(v).toString('base64'));" ++ "enc.map(v => zlib.inflateRawSync(Buffer.from(v, 'base64')).toString())"), ++ njs_str("WAKA,αβγ") }, + + { njs_str("const zlib = require('zlib');" +- "['WAKA', 'αβγ']" +- ".map(v => zlib.deflateRawSync(v, {dictionary: Buffer.from('WAKA')}).toString('base64'))"), +- njs_str("CwdiAA==,O7fx3KZzmwE=") }, ++ "const enc = ['WAKA', 'αβγ']" ++ ".map(v => zlib.deflateRawSync(v, {dictionary: Buffer.from('WAKA')}).toString('base64'));" ++ "enc.map(v => zlib.inflateRawSync(Buffer.from(v, 'base64'), {dictionary: Buffer.from('WAKA')}))"), ++ njs_str("WAKA,αβγ") }, + + { njs_str("const zlib = require('zlib');" + "['WAKA', 'αβγ']" diff --git a/njs.spec b/njs.spec index ba23806..1625e9e 100644 --- a/njs.spec +++ b/njs.spec @@ -25,6 +25,10 @@ URL: https://github.com/%{gh_owner}/%{project} Source0: https://github.com/%{gh_owner}/%{project}/archive/%{gh_commit}/%{project}-%{version}-%{gh_short}.tar.gz +# Fix the test-suite with zlib-ng +# See https://github.com/nginx/njs/issues/704 +Patch0: github704.patch + BuildRequires: make BuildRequires: gcc BuildRequires: openssl-devel @@ -59,6 +63,7 @@ Library and include files required for libnjs. %prep %setup -qn %{project}-%{gh_commit} +%patch -P0 -p1 %build @@ -108,6 +113,8 @@ make test %{?_smp_mflags} %changelog * Tue Apr 16 2024 Remi Collet - 0.8.4-1 - update to 0.8.4 +- report test failure with zlib-ng + https://github.com/nginx/njs/issues/704 * Thu Feb 8 2024 Remi Collet - 0.8.3-1 - update to 0.8.3 -- cgit