From 7433c3df2ebffcc630cee0fd3bf4db52ea4c7b81 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Mon, 25 May 2026 10:24:15 +0200 Subject: [PATCH] zlib: coerce -0 to +0 for crc32 seeds Signed-off-by: Filip Skokan PR-URL: https://github.com/nodejs/node/pull/63556 Reviewed-By: Jordan Harband Reviewed-By: Chemi Atlow --- lib/zlib.js | 2 ++ test/parallel/test-zlib-negative-zero.js | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 test/parallel/test-zlib-negative-zero.js diff --git a/lib/zlib.js b/lib/zlib.js index 056b1a13a17..d4f2446a597 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -969,6 +969,8 @@ function crc32(data, value = 0) { throw new ERR_INVALID_ARG_TYPE('data', ['Buffer', 'TypedArray', 'DataView', 'string'], data); } validateUint32(value, 'value'); + // Coerce -0 to +0. + value += 0; return crc32Native(data, value); } diff --git a/test/parallel/test-zlib-negative-zero.js b/test/parallel/test-zlib-negative-zero.js new file mode 100644 index 00000000000..dc9cc3175d2 --- /dev/null +++ b/test/parallel/test-zlib-negative-zero.js @@ -0,0 +1,8 @@ +'use strict'; + +require('../common'); + +const assert = require('assert'); +const zlib = require('zlib'); + +assert.strictEqual(zlib.crc32('', -0), zlib.crc32('', 0));