Commit Graph
213 Commits
Author SHA1 Message Date
Xia Chao 1e0167d7d6 zlib: preserve brotli params and dictionary on reset
ResetStream currently calls Init() with no arguments, which drops
the stored dictionary and never replays SetParams. Remember each
successful parameter and replay both the dictionary and the params
when the stream is reset.

Fixes: https://github.com/nodejs/node/issues/66156
Signed-off-by: Xia Chao <shapirolutts@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66157
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-09-26 18:28:05 +00:00
Xia Chao ca0810fd80 zlib: reject reset after gzip/deflate emitted incomplete output
deflateReset starts a new member. Bytes already written out cannot be
taken back, so gunzip/inflate see a truncated member followed by a new
header. Refuse reset in that case. Raw deflate has no wrapper header
and is unchanged.

Signed-off-by: Xia Chao <shapirolutts@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66179
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-09-26 18:27:53 +00:00
Xia Chao 402889cfb8 zlib: reject reset while a zstd frame is incomplete
Resetting a ZstdCompress stream while a frame is still in
progress dropped the frame state, but any bytes already
written out stayed at the start of the output stream. The
next frame was then appended to that fragment, so the
resulting stream could not be decompressed. The failure was
silent: the compressor reported no error at all.

ZSTD_reset_session_only cancels unflushed internal data, so
refuse reset only when the incomplete frame has already
emitted output.

Signed-off-by: Xia Chao <shapirolutts@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66088
Reviewed-By: James M Snell <jasnell@gmail.com>
2026-09-25 13:49:29 +00:00
James M Snell c14304154e zlib: reject invalid zstd dictionaries
Signed-off-by: James M Snell <jsnell@cloudflare.com>
PR-URL: https://github.com/nodejs/node/pull/65867
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2026-09-11 14:57:09 +00:00
James M Snell 4051baeaef zlib: fix zstd reset
Preserve dictionaries and params when zstd is reset.

Update missing documentation.

Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65867
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
2026-09-11 14:57:07 +00:00
James M Snell 7055c484ff zlib: improve zstd decoding across chunk boundaries
Discovered when testing some other changes that zstd was not
handling certain chunk boundaries very well. This fixes it.

- Decodes concatenated and skippable zstd frames across all
  chunk boundaries.
- Preserves rejectGarbageAfterEnd semantics.
- Reports corruption in subsequent frames.
- Handles trailing partial frame identifiers consistently.
- Covers classic sync/async and iterable APIs.
- Updated documentation and internal typings.

Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Opencode
PR-URL: https://github.com/nodejs/node/pull/65865
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2026-09-08 23:49:10 +00:00
Archkon c3de450f26 zlib: validate pledgedSrcSize for sync zstd
Zstd replaces a configured pledged source size with the input size when
the first call to ZSTD_compressStream2() uses ZSTD_e_end. Track consumed
input in Node and report ZSTD_error_srcSize_wrong when the completed
frame does not match the original pledge.

Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/64601
Fixes: https://github.com/nodejs/node/issues/64600
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
2026-08-08 08:57:54 -04:00
RafaelGSS 4b482c5c21 zlib: throw on out-of-bounds write buffers
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: https://github.com/nodejs-private/node-private/pull/931
Refs: https://hackerone.com/reports/3857258
CVE-ID: CVE-2026-58045
2026-07-29 10:42:12 -03:00
Archkon de6eeece8f zlib: validate pledgedSrcSize as a safe integer
pledgedSrcSize represents an exact byte count. Reject values that are
not non-negative safe integers instead of silently ignoring or coercing
them through IntegerValue().

Apply the same validation to zlib/iter and retain a native validation
check for internal callers.

Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/64604
Fixes: https://github.com/nodejs/node/issues/64603
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Jan Martin <jan.krems@gmail.com>
2026-07-23 22:17:50 +00:00
Archkon 8c1d1284cd zlib: reject truncated zstd input
Treat an unfinished Zstd frame as an unexpected end of file when the
stream is finalized with ZSTD_e_end.

Avoid reporting an error while the output buffer still needs to be
drained or when an empty final write follows a completed frame. Preserve
partial decompression when ZSTD_e_flush is used.

Signed-off-by: Archkon <180910180+Archkon@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/64593
Fixes: https://github.com/nodejs/node/issues/64592
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ryuhei Shima <shimaryuhei@gmail.com>
2026-07-21 05:41:42 +00:00
Filip Skokan 7c43441222 zlib: reject trailing gzip members in web streams
Pass the existing rejectGarbageAfterEnd option through to the native
zlib context and skip gunzip's concatenated-member loop when it is set.
This lets DecompressionStream reject a second gzip member as trailing
input while preserving default zlib gunzip behavior.

Also make the sync zlib path honor rejectGarbageAfterEnd when native
decompression leaves unused input, covering Brotli as well.

Fixes: https://github.com/nodejs/node/issues/58247

Signed-off-by: Filip Skokan <panva.ip@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/64023
Fixes: https://github.com/nodejs/node/issues/58247
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2026-06-27 11:22:31 +00:00
Nora Dossche 458c37b019 src: fix edge case when deflateInit2() fails with Z_VERSION_ERROR
This function call can fail with `Z_VERSION_ERROR` if the compiled
library vs loaded library mismatched in version number or in
stream structure size.
In those cases, zlib doesn't initialize the `strm_.msg` field to
null. Therefore, when a `CompressionError` object is created via
`ErrorForMessage()`, it can read a stale or uninitialized `strm_.msg`
pointer that will cause a crash.

Example ASAN report:
```
AddressSanitizer: SEGV on unknown address
    #0 __strlen_avx2
        string/../sysdeps/x86_64/multiarch/strlen-avx2.S:76
    #1 strlen (/work/node/out/Debug/node+0x1a42ab7)
    #2 v8::(anonymous namespace)::StringLength(char const*)
        /work/node/out/../deps/v8/src/api/api.cc:7581:16
    #3 v8::(anonymous namespace)::StringLength(unsigned char const*)
        /work/node/out/../deps/v8/src/api/api.cc:7587:10
    #4 v8::String::NewFromOneByte(v8::Isolate*,
        unsigned char const*, v8::NewStringType, int)
        /work/node/out/../deps/v8/src/api/api.cc:7677:3
    #5 node::OneByteString(v8::Isolate*,
        char const*, int, v8::NewStringType)
        /work/node/out/../src/util-inl.h:166:10
    #6 node::(anonymous namespace)::CompressionStream<
        node::(anonymous namespace)::ZlibContext>
        ::EmitError(node::(anonymous namespace)
        ::CompressionError const&)
        /work/node/out/../src/node_zlib.cc:565:7
    #7 node::(anonymous namespace)::CompressionStream<
        node::(anonymous namespace)::ZlibContext>
        ::CheckError()
        /work/node/out/../src/node_zlib.cc:519:5
    #8 node::(anonymous namespace)::CompressionStream<
        node::(anonymous namespace)::ZlibContext>
        ::AfterThreadPoolWork(int)
        /work/node/out/../src/node_zlib.cc:543:10
    #9 node::ThreadPoolWork::ScheduleWork()
        ::'lambda'(uv_work_s*, int)
        ::operator()(uv_work_s*, int) const
        /work/node/out/../src/threadpoolwork-inl.h:57:15
    #10 node::ThreadPoolWork::ScheduleWork()
        ::'lambda'(uv_work_s*, int)
        ::__invoke(uv_work_s*, int)
        /work/node/out/../src/threadpoolwork-inl.h:48:7
    #11 uv__work_done /work/libuv-1.51.0/src/threadpool.c:330:5
    #12 uv__async_io.part.0
        /work/libuv-1.51.0/src/unix/async.c:208:5
```

Signed-off-by: ndossche <nora.dossche@ugent.be>
PR-URL: https://github.com/nodejs/node/pull/63476
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2026-06-02 13:00:09 +00:00
Matteo Collina 53bcd114b1 zlib: fix use-after-free when reset() is called during write
The Reset() method did not check the write_in_progress_ flag before
resetting the compression stream. This allowed reset() to free the
compression library's internal state while a worker thread was still
using it during an async write, causing a use-after-free.

Add a write_in_progress_ guard to Reset() that throws an error if a
write is in progress, matching the existing pattern used by Close()
and Write().

PR-URL: TODO
Refs: https://hackerone.com/reports/3609132
PR-URL: https://github.com/nodejs/node/pull/62325
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2026-03-26 22:18:32 +00:00
Andy Weiss 8f613eea13 zlib: add support for brotli compression dictionary
This change adds JS API support for custom compression dictionaries
with Brotli in the zlib library. The underlying Brotli dependency
already supports this and zstd exposes something similar.
This follows the zstd approach for using a custom dictionary but
for Brotli.

Fixes: https://github.com/nodejs/node/issues/52250
PR-URL: https://github.com/nodejs/node/pull/61763
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-02-13 16:10:17 +00:00
Anna Henningsen 8ba4d727a8 src: track allocations made by zstd streams
This is both valuable as a diagnostic tool and as a way to inform
the JS runtime about external allocations.

Currently, this is a feature only enabled in the statically linked
builds of zstd, so with `--shared-zstd`, we fall back to the
non-tracking variant.

PR-URL: https://github.com/nodejs/node/pull/61717
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2026-02-09 20:42:56 +00:00
Anna Henningsen e8b5fb6129 src: do not store compression methods on Brotli classes
This addresses a long-standing TODO comment, referencing the fact
that these values are either known at compile time or can be
inferred from the `this` value in the context class.

PR-URL: https://github.com/nodejs/node/pull/61717
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2026-02-09 20:42:55 +00:00
Anna Henningsen fb4154902f src: extract zlib allocation tracking into its own class
This makes it a bit easier to separate concerns, and results in
reduced code duplication when compiling since this code does not
depend on template parameters.

PR-URL: https://github.com/nodejs/node/pull/61717
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2026-02-09 20:42:53 +00:00
Anna Henningsen 6df454be70 src: release memory for zstd contexts in Close()
This aligns zstd streams with other compression libraries in this
regard, and enables releasing memory early when the stream ends in
JS instead of waiting for GC to clean up the wrapper object (which
is a problem that is exacerbated in the zstd context because we
do not track memory and report memory pressure to V8 yet).

PR-URL: https://github.com/nodejs/node/pull/61717
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2026-02-09 20:42:53 +00:00
Ryuhei Shima 2679b62e91 zlib: validate write_result array length
Fixes: https://github.com/nodejs/node/issues/61286
PR-URL: https://github.com/nodejs/node/pull/61342
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-01-15 00:38:09 +00:00
Matteo Collina ce2ec3d835 zlib: add CHECK to validate fast path input
PR-URL: https://github.com/nodejs/node/pull/61175
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2025-12-30 19:03:23 +00:00
jhofstee 54c456702c zlib: reduce code duplication
The offset in the allocated memory was calculated in alloc and free,
this makes it a single constant so it only needs to be defined once.

PR-URL: https://github.com/nodejs/node/pull/57810
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2025-09-22 20:53:01 +00:00
Gürgün Dayıoğlu c85460b0ad zlib: implement fast path for crc32
PR-URL: https://github.com/nodejs/node/pull/59813
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2025-09-14 00:39:58 +00:00
Yaksh Bariya d58343ec48 src: correctly report memory changes to V8
Call `V8::ExternalMemoryAccounter::Update` instead of
`V8::ExternalMemoryAccounter::Increase` to report memory difference to
V8

Calling `V8::ExternalMemoryAccounter::Increase` with a signed integer on
32-bit platforms causes instances where GC inside GC takes place leading
to a crash in certain cases.

During GC, native objects are destructed. In destructor for
`CompressionStream` class used by zlib, memory release information is
passed onto `V8::ExternalMemoryAccounter::Increase()` instead of
`V8::ExternalMemoryAccounter::Decrease()` which triggers V8's memory
limits, thus triggering GC inside GC which leads to crash.

Bug initially introduced in commit
1d5d7b6eed

For full report see https://hackerone.com/reports/3302484

PR-URL: https://github.com/nodejs/node/pull/59623
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2025-09-09 12:17:47 +00:00
lluisemper b8e643259e zlib: add dictionary support to zstdCompress and zstdDecompress
Adds optional dictionary support to zlib’s zstdCompress and
zstdDecompress APIs. This enables better compression ratios when the
dictionary matches expected input structure or content patterns.

The implementation allows passing a `dictionary` buffer through the
options object. Support was added to both streaming and convenience
methods. Tests and documentation were also updated to reflect this new
capability.

Fixes: https://github.com/nodejs/node/issues/59105
PR-URL: https://github.com/nodejs/node/pull/59240
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2025-08-04 16:13:57 +00:00
Aditi faada65d16 src: add FromV8Value<T>() for integral and enum types
Add a template utility method FromV8Value<T>() to replace the
repetitive static_cast<...>(value.As<>()‑>Value()) pattern.
It also additionally adds compile‑time range checks for
integers.

Refs: https://github.com/nodejs/node/pull/57146#discussion_r1963799600
PR-URL: https://github.com/nodejs/node/pull/57931
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2025-06-24 04:16:09 +00:00
Michaël Zasso 742c0eb126 src: use v8::ExternalMemoryAccounter
`Isolate::AdjustAmountOfExternalAllocatedMemory` is deprecated.

Refs: https://github.com/v8/v8/commit/7dc4c181956be958e98ecd6bfe7ec636b4b23c62
PR-URL: https://github.com/nodejs/node/pull/58070
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2025-05-02 15:10:37 +02:00
jhofstee dc035bbc9b zlib: fix pointer alignment
The function AllocForBrotli prefixes the allocated memory with its
size, and returns a pointer to the region after it. This pointer can
however no longer be suitably aligned. Correct this by allocating
the maximum of the the size of the size_t and the max alignment.

On Arm 32bits the size_t is 4 bytes long, but the alignment is 8 for
some NEON instructions. When Brotli is compiled with optimizations
enabled newer GCC versions will use the NEON instructions and trigger
a bus error killing node.

see https://github.com/google/brotli/issues/1159

PR-URL: https://github.com/nodejs/node/pull/57727
Reviewed-By: Shelley Vohr <shelley.vohr@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
2025-04-09 10:24:13 +00:00
Michaël Zasso 3186468bed src: use args.This() in zlib
Refs: https://github.com/nodejs/node/pull/53474
PR-URL: https://github.com/nodejs/node/pull/56988
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
2025-02-11 07:26:46 +00:00
Jan Krems bf12d72faa zlib: add zstd support
Fixes: https://github.com/nodejs/node/issues/48412
PR-URL: https://github.com/nodejs/node/pull/52100
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2025-02-08 12:43:53 +00:00
Yagiz Nizipli 317d2450f9 src: modernize likely/unlikely hints
PR-URL: https://github.com/nodejs/node/pull/55155
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2024-09-30 18:04:16 +00:00
Yagiz Nizipli 5b3f3c5a3b zlib: throw brotli initialization error from c++
PR-URL: https://github.com/nodejs/node/pull/54698
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-09-21 09:23:59 -07:00
Michaël Zasso c93e256ee7 src: use args.This() instead of Holder
The latter is deprecated in V8.

Refs: http://crbug.com/333672197
PR-URL: https://github.com/nodejs/node/pull/53474
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
2024-06-18 16:02:42 +00:00
Joyee Cheung 2cfabb11e1 zlib: expose zlib.crc32()
This patch exposes the crc32() function from zlib to user-land.

It computes a 32-bit Cyclic Redundancy Check checksum of `data`. If
`value` is specified, it is used as the starting value of the checksum,
otherwise, 0 is used as the starting value.

```js
const zlib = require('node:zlib');
const { Buffer } = require('node:buffer');

let crc = zlib.crc32('hello');  // 907060870
crc = zlib.crc32('world', crc);  // 4192936109

crc = zlib.crc32(Buffer.from('hello'));  // 907060870
crc = zlib.crc32(Buffer.from('world'), crc);  // 4192936109
```

PR-URL: https://github.com/nodejs/node/pull/52692
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-05-02 12:54:46 +00:00
Joyee Cheung 5f2539cd9a src: cast v8::Object::GetInternalField() return value to v8::Value
In preparation of https://chromium-review.googlesource.com/c/v8/v8/+/4707972
which changes the return value to v8::Data.

PR-URL: https://github.com/nodejs/node/pull/48943
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
2023-08-02 02:14:35 +00:00
Tobias Nießen f0e645321c src: use UNREACHABLE instead of CHECK(falsy)
Also remove some dead code following such statements.

PR-URL: https://github.com/nodejs/node/pull/46317
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2023-01-25 14:00:21 +00:00
Tobias Nießen c47ad5815d src: use explicit C++17 fallthrough
This passes the strictest -Wimplicit-fallthrough setting.

PR-URL: https://github.com/nodejs/node/pull/46251
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2023-01-20 13:04:52 +00:00
legendecas 71ff89f929 src: rename internal module declaration as internal bindings
This is a continuation of the name reification on the internal bindings.

Renames NODE_MODULE_CONTEXT_AWARE_INTERNAL and
NODE_MODULE_EXTERNAL_REFERENCE to NODE_BINDING_CONTEXT_AWARE_INTERNAL
and NODE_BINDING_EXTERNAL_REFERENCE respectively.

PR-URL: https://github.com/nodejs/node/pull/45551
Refs: https://github.com/nodejs/node/issues/44036
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2022-11-29 00:23:08 +08:00
theanarkh 8fb282e2b4 src: trace threadpool event
PR-URL: https://github.com/nodejs/node/pull/44458
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
2022-11-01 04:21:13 +00:00
Anna Henningsen ee75ad7a38 src: use if constexpr where appropriate
Doesn't change much but communicates to readers that these
are compile-time conditionals.

PR-URL: https://github.com/nodejs/node/pull/44291
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2022-08-27 09:51:35 +00:00
Keyhan Vakil 8c35a4e4e6 src: remove unowned usages of GetBackingStore
This removes all usages of GetBackingStore without any entries in the
`CODEOWNERS` file. For the most part this is a pretty straightforward
review; except `SPREAD_BUFFER_ARG` and the changes to `CopyArrayBuffer`.

See the linked issue for an explanation.

Refs: https://github.com/nodejs/node/issues/32226
Refs: https://github.com/nodejs/node/pull/43921
PR-URL: https://github.com/nodejs/node/pull/44080
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2022-08-03 06:45:45 +00:00
legendecas a7e5b413ef src: split property helpers from node::Environment
PR-URL: https://github.com/nodejs/node/pull/44056
Refs: https://github.com/nodejs/node/issues/42528
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
2022-08-02 00:01:02 +08:00
Anna Henningsen 72e83fcea6 src: perform minor cleanups on zlib code
- Use `final` to indicate the classes that we actually
  instantiate
- Properly use `const` (and the necessary associated `const_cast`
  for zlib because we don’t define `ZLIB_CONST` and allow shared
  builds)
- Store the JS callback in an internal field rather than a `Global`
  (which improves memory leak debugging capabilities, removes
  a potential future memory leak footgun, and aligns the code
  with the rest of the codebase more closely)
- Other minor C++ cleanup

PR-URL: https://github.com/nodejs/node/pull/42247
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
2022-03-10 11:51:12 +00:00
Joyee Cheung 58b7d47ad2 src: register zlib external references for snapshot
PR-URL: https://github.com/nodejs/node/pull/40050
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
2021-09-16 09:39:15 -04:00
XadillaX f179eb01af src,zlib: tighten up Z_*_WINDOWBITS macros
PR-URL: https://github.com/nodejs/node/pull/39115
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2021-06-30 11:37:22 +08:00
James M Snell 28fe1ef635 src: reduce duplicated boilerplate with new env utility fn
Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/36536
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2021-01-03 12:58:09 -08:00
Andrey Pechkurov f8eaeb0c8e zlib: switch to lazy init for zlib streams
PR-URL: https://github.com/nodejs/node/pull/34048
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2020-07-22 16:20:33 +03:00
Daniel Bevenius 4a20cc937f src: remove unused using declarations
This commit removes the unused using declarations reported by lint-cpp.

PR-URL: https://github.com/nodejs/node/pull/33268
Refs: https://github.com/nodejs/node/issues/29226
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Christian Clauss <cclauss@me.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>
2020-05-28 10:02:14 -04:00
Ben Noordhuis b8ed2a07d3 src: fix invalid windowBits=8 gzip segfault
`{ windowBits: 8 }` is legal for deflate streams but not gzip streams.
Fix a nullptr dereference when formatting the error message.

Bug introduced in commit c34eae5f88 ("zlib: refactor zlib internals")
from September 2018.

PR-URL: https://github.com/nodejs/node/pull/33045
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: David Carlier <devnexen@gmail.com>
2020-05-09 07:54:38 +02:00
James M Snell 0fac393d26 src: improve handling of internal field counting
Change suggested by bnoordhuis.

Improve handing of internal field counting by using enums.
Helps protect against future possible breakage if field
indexes are ever changed or added to.

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/31960
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2020-03-02 10:58:36 -08:00
ConorDavenport 99c8c6d80f src: remove duplicate field env in CryptoJob class
Removed field env from cryptojob class, replaced with
function env() inherited from ThreadPoolWork

PR-URL: https://github.com/nodejs/node/pull/31554
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2020-02-02 09:06:42 -08:00