From a4787636cb4687c848e067557ff9765bc4902938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Inf=C3=BChr?= Date: Mon, 12 Oct 2026 15:13:31 +0200 Subject: [PATCH 01/24] deps: V8: cherry-pick 497c2e6a2434 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: [heap] Always decrement age in RetainMaps() When the prototype and constructor were already marked we did not age the map because of the assumption that this would only keep the transition tree alive. However, this does not hold because of the JSFunctions inside an AccessorPair in DescriptorArray. This can result in retaining maps indefinitely when not triggering memory reducing GCs. This CL therefore simplifies the code to always age maps instead. This is neutral on Speedometer and Jetstream. Bug: 571157135 Change-Id: I8fb633a0ec0c1d66e4596390ca48e1c7006c9cc2 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8557820 Commit-Queue: Dominik Inführ Reviewed-by: Michael Lippautz Cr-Commit-Position: refs/heads/main@{#110622} Refs: https://github.com/v8/v8/commit/497c2e6a2434af02b44417b55b1576702922f5e9 PR-URL: https://github.com/nodejs/node/pull/66728 Reviewed-by: Antoine du Hamel --- common.gypi | 2 +- deps/v8/src/heap/mark-compact.cc | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/common.gypi b/common.gypi index f8588b823119..91efcb7cb87b 100644 --- a/common.gypi +++ b/common.gypi @@ -50,7 +50,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.11', + 'v8_embedder_string': '-node.12', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/heap/mark-compact.cc b/deps/v8/src/heap/mark-compact.cc index 6712456d29aa..dcb0712a1871 100644 --- a/deps/v8/src/heap/mark-compact.cc +++ b/deps/v8/src/heap/mark-compact.cc @@ -2539,17 +2539,7 @@ void MarkCompactCollector::RetainMaps() { MarkingHelper::WorklistTarget::kRegular, map); } } - Tagged prototype = map->prototype(); - if (age > 0 && IsHeapObject(prototype) && - MarkingHelper::IsUnmarkedAndNotAlwaysLive( - heap_, marking_state_, Cast(prototype))) { - // The prototype is not marked, age the map. - new_age = age - 1; - } else { - // The prototype and the constructor are marked, this map keeps only - // transition tree alive, not JSObjects. Do not age the map. - new_age = age; - } + new_age = age > 0 ? age - 1 : 0; } else { new_age = v8_flags.retain_maps_for_n_gc; } From f775f92e2e82b08fc96966afc5fff3613361194f Mon Sep 17 00:00:00 2001 From: Austin Burdine Date: Thu, 8 Oct 2026 09:25:54 -0400 Subject: [PATCH 02/24] deps: V8: backport 2444c109f4f8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: [heap] Treat zero allocation throughput as a low allocation rate Since https://crrev.com/c/5935313 allocation throughput is tracked with SmoothedBytesAndDuration, which has no lower bound. A sampled throughput of exactly 0 -- nothing was allocated, or the smoothed value decayed to 0 after a long idle period -- made ComputeMutatorUtilizationImpl() return a mutator utilization of 0 ("maximal allocation"). For an isolate that never allocates on the CppHeap, HasLowAllocationRate() is then never true and the MemoryReducer cannot start a GC through its low-allocation condition; only the 100s watchdog can. Node.js hits this for any process that does not use node:vm. Remove the special case. A mutator speed of 0 now yields a mutator utilization of 1, i.e. the lowest possible allocation rate. gc_speed is either the conservative default or at least 1 byte/ms, so the formula stays well defined. Bug: 570738027 Change-Id: I84cd51607df3c31c2f1e02bb2fe258e5506131ce Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8521518 Reviewed-by: Dominik Inführ Commit-Queue: Dominik Inführ Reviewed-by: Omer Katz Commit-Queue: Omer Katz Cr-Commit-Position: refs/heads/main@{#110599} Refs: https://github.com/v8/v8/commit/2444c109f4f8165024971e15b12eb4611b4cd676 Co-authored-by: Antoine du Hamel Reviewed-by: Antoine du Hamel PR-URL: https://github.com/nodejs/node/pull/66736 --- common.gypi | 2 +- deps/v8/AUTHORS | 1 + deps/v8/src/heap/gc-tracer.h | 2 + deps/v8/src/heap/heap.cc | 2 - deps/v8/src/heap/heap.h | 2 +- .../test/unittests/heap/gc-tracer-unittest.cc | 39 +++++++++++++++++++ 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/common.gypi b/common.gypi index 91efcb7cb87b..2ba1394a1c32 100644 --- a/common.gypi +++ b/common.gypi @@ -50,7 +50,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.12', + 'v8_embedder_string': '-node.13', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/AUTHORS b/deps/v8/AUTHORS index 31ac08aa8ddb..e41b272bb03a 100644 --- a/deps/v8/AUTHORS +++ b/deps/v8/AUTHORS @@ -80,6 +80,7 @@ Artem Kobzar Arthur Islamov Asuka Shikina Aurèle Barrière +Austin Burdine Aviv Keller Ayako Hayasaka Bala Avulapati diff --git a/deps/v8/src/heap/gc-tracer.h b/deps/v8/src/heap/gc-tracer.h index 453ab94e4b14..ffa5d7d0e68e 100644 --- a/deps/v8/src/heap/gc-tracer.h +++ b/deps/v8/src/heap/gc-tracer.h @@ -692,6 +692,7 @@ class V8_EXPORT_PRIVATE GCTracer { FRIEND_TEST(GCTracerTest, BackgroundMajorMCScope); FRIEND_TEST(GCTracerTest, CyclePriorities); FRIEND_TEST(GCTracerTest, EmbedderAllocationThroughput); + FRIEND_TEST(GCTracerTest, HighAllocationRateWithEmbedderAllocation); FRIEND_TEST(GCTracerTest, MultithreadedBackgroundScope); FRIEND_TEST(GCTracerTest, NewSpaceAllocationThroughput); FRIEND_TEST(GCTracerTest, PerGenerationAllocationThroughput); @@ -700,6 +701,7 @@ class V8_EXPORT_PRIVATE GCTracer { FRIEND_TEST(GCTracerTest, IncrementalMarkingDetails); FRIEND_TEST(GCTracerTest, IncrementalScope); FRIEND_TEST(GCTracerTest, IncrementalMarkingSpeed); + FRIEND_TEST(GCTracerTest, LowAllocationRateWithZeroEmbedderAllocation); FRIEND_TEST(GCTracerTest, MutatorUtilization); FRIEND_TEST(GCTracerTest, RecordMarkCompactHistograms); FRIEND_TEST(GCTracerTest, RecordScavengerHistograms); diff --git a/deps/v8/src/heap/heap.cc b/deps/v8/src/heap/heap.cc index 420c631486d5..a925a9eb1773 100644 --- a/deps/v8/src/heap/heap.cc +++ b/deps/v8/src/heap/heap.cc @@ -3489,9 +3489,7 @@ namespace { double ComputeMutatorUtilizationImpl(double mutator_speed, std::optional gc_speed) { - constexpr double kMinMutatorUtilization = 0.0; constexpr double kConservativeGcSpeedInBytesPerMillisecond = 200000; - if (mutator_speed == 0) return kMinMutatorUtilization; if (!gc_speed) gc_speed = kConservativeGcSpeedInBytesPerMillisecond; // Derivation: // mutator_utilization = mutator_time / (mutator_time + gc_time) diff --git a/deps/v8/src/heap/heap.h b/deps/v8/src/heap/heap.h index 39e2304d2a2e..944230ba4dc7 100644 --- a/deps/v8/src/heap/heap.h +++ b/deps/v8/src/heap/heap.h @@ -695,7 +695,7 @@ class Heap final { // null. V8_INLINE bool CanSafepoint() const { return deserialization_complete(); } - bool HasLowAllocationRate(); + V8_EXPORT_PRIVATE bool HasLowAllocationRate(); bool HasHighFragmentation(); void ActivateMemoryReducerIfNeeded(); diff --git a/deps/v8/test/unittests/heap/gc-tracer-unittest.cc b/deps/v8/test/unittests/heap/gc-tracer-unittest.cc index 0a3c311f01f4..54e46df2cc76 100644 --- a/deps/v8/test/unittests/heap/gc-tracer-unittest.cc +++ b/deps/v8/test/unittests/heap/gc-tracer-unittest.cc @@ -218,6 +218,45 @@ TEST_F(GCTracerTest, IncrementalScope) { tracer->current_.scopes[GCTracer::Scope::MC_INCREMENTAL]); } +TEST_F(GCTracerTest, LowAllocationRateWithZeroEmbedderAllocation) { + if (v8_flags.stress_incremental_marking) return; + Heap* heap = i_isolate()->heap(); + GCTracer* tracer = heap->tracer(); + tracer->ResetForTesting(); + tracer->allocation_time_ = base::TimeTicks(); + + // Two samples 100 ms apart. Young and old generation allocate a little; + // the embedder (CppHeap) and external memory allocate nothing at all, as + // in an embedder that never uses cppgc (e.g. Node.js without node:vm). + tracer->SampleAllocation(base::TimeTicks::FromMsTicksForTesting(0), 0, 0, 0, + 0); + tracer->SampleAllocation(base::TimeTicks::FromMsTicksForTesting(100), 100, + 100, 0, 0); + + EXPECT_DOUBLE_EQ(0.0, + tracer->EmbedderAllocationThroughputInBytesPerMillisecond()); + EXPECT_TRUE(heap->HasLowAllocationRate()); +} + +TEST_F(GCTracerTest, HighAllocationRateWithEmbedderAllocation) { + if (v8_flags.stress_incremental_marking) return; + Heap* heap = i_isolate()->heap(); + GCTracer* tracer = heap->tracer(); + tracer->ResetForTesting(); + tracer->allocation_time_ = base::TimeTicks(); + + // Same as above, but the embedder allocates heavily: 1 GB over 100 ms is + // ~10^7 B/ms, so the embedder term must still report a high allocation + // rate (mu = 200000 / (10^7 + 200000) < 0.993). + tracer->SampleAllocation(base::TimeTicks::FromMsTicksForTesting(0), 0, 0, 0, + 0); + tracer->SampleAllocation(base::TimeTicks::FromMsTicksForTesting(100), 100, + 100, size_t{1} << 30, 0); + + EXPECT_GT(tracer->EmbedderAllocationThroughputInBytesPerMillisecond(), 0.0); + EXPECT_FALSE(heap->HasLowAllocationRate()); +} + TEST_F(GCTracerTest, IncrementalMarkingDetails) { if (v8_flags.stress_incremental_marking) return; GCTracer* tracer = i_isolate()->heap()->tracer(); From a92ee337b123b3c9d5db986130a1b50f8022e48e Mon Sep 17 00:00:00 2001 From: "Node.js GitHub Bot" Date: Wed, 11 Nov 2026 12:21:27 -0500 Subject: [PATCH 03/24] deps: update nghttp3 to 1.19.0 PR-URL: https://github.com/nodejs/node/pull/67333 Reviewed-By: Colin Ihrig Reviewed-By: Tim Perry --- .../nghttp3/lib/includes/nghttp3/nghttp3.h | 21 ++- .../nghttp3/lib/includes/nghttp3/version.h | 4 +- deps/ngtcp2/nghttp3/lib/nghttp3_balloc.c | 2 +- deps/ngtcp2/nghttp3/lib/nghttp3_buf.c | 12 +- deps/ngtcp2/nghttp3/lib/nghttp3_conn.c | 44 ++++--- deps/ngtcp2/nghttp3/lib/nghttp3_frame.c | 28 ++-- deps/ngtcp2/nghttp3/lib/nghttp3_frame.h | 2 + deps/ngtcp2/nghttp3/lib/nghttp3_map.c | 93 +++++-------- deps/ngtcp2/nghttp3/lib/nghttp3_map.h | 4 +- deps/ngtcp2/nghttp3/lib/nghttp3_qpack.c | 123 +++++++++--------- deps/ngtcp2/nghttp3/lib/nghttp3_ratelim.c | 19 ++- deps/ngtcp2/nghttp3/lib/nghttp3_ratelim.h | 7 +- deps/ngtcp2/nghttp3/lib/nghttp3_stream.h | 5 +- deps/ngtcp2/nghttp3/lib/nghttp3_unreachable.h | 6 +- 14 files changed, 192 insertions(+), 178 deletions(-) diff --git a/deps/ngtcp2/nghttp3/lib/includes/nghttp3/nghttp3.h b/deps/ngtcp2/nghttp3/lib/includes/nghttp3/nghttp3.h index d3dd9217d4b0..77ae851ae594 100644 --- a/deps/ngtcp2/nghttp3/lib/includes/nghttp3/nghttp3.h +++ b/deps/ngtcp2/nghttp3/lib/includes/nghttp3/nghttp3.h @@ -1871,12 +1871,13 @@ typedef struct nghttp3_settings { NGHTTP3_SETTINGS_V3. */ /** * :member:`glitch_ratelim_burst` is the maximum number of tokens - * available to "glitch" rate limiter. "glitch" is a suspicious - * activity from a remote endpoint. If detected, certain amount of - * tokens are consumed. If no tokens are available to consume, the - * connection is closed. The rate of token generation is specified - * by :member:`glitch_ratelim_rate`. This feature is enabled only - * when `nghttp3_conn_read_stream2` is used. + * available to "glitch" rate limiter. It is clamped to UINT64_MAX + * / NGHTTP3_SECONDS. "glitch" is a suspicious activity from a + * remote endpoint. If detected, certain amount of tokens are + * consumed. If no tokens are available to consume, the connection + * is closed. The rate of token generation is specified by + * :member:`glitch_ratelim_rate`. This feature is enabled only when + * `nghttp3_conn_read_stream2` is used. * * .. version-added:: 1.12.0 */ @@ -3089,6 +3090,8 @@ typedef struct nghttp3_data_reader { * Stream has already been opened. * :macro:`NGHTTP3_ERR_NOMEM` * Out of memory. + * :macro:`NGHTTP3_ERR_INVALID_ARGUMENT` + * The required memory for |nva| of length |nvlen| is too large. */ NGHTTP3_EXTERN int nghttp3_conn_submit_request( nghttp3_conn *conn, int64_t stream_id, const nghttp3_nv *nva, size_t nvlen, @@ -3108,6 +3111,8 @@ NGHTTP3_EXTERN int nghttp3_conn_submit_request( * Stream not found * :macro:`NGHTTP3_ERR_NOMEM` * Out of memory. + * :macro:`NGHTTP3_ERR_INVALID_ARGUMENT` + * The required memory for |nva| of length |nvlen| is too large. */ NGHTTP3_EXTERN int nghttp3_conn_submit_info(nghttp3_conn *conn, int64_t stream_id, @@ -3130,6 +3135,8 @@ NGHTTP3_EXTERN int nghttp3_conn_submit_info(nghttp3_conn *conn, * Stream not found * :macro:`NGHTTP3_ERR_NOMEM` * Out of memory. + * :macro:`NGHTTP3_ERR_INVALID_ARGUMENT` + * The required memory for |nva| of length |nvlen| is too large. */ NGHTTP3_EXTERN int nghttp3_conn_submit_response(nghttp3_conn *conn, int64_t stream_id, @@ -3154,6 +3161,8 @@ NGHTTP3_EXTERN int nghttp3_conn_submit_response(nghttp3_conn *conn, * Application has already submitted fin to stream. * :macro:`NGHTTP3_ERR_NOMEM` * Out of memory. + * :macro:`NGHTTP3_ERR_INVALID_ARGUMENT` + * The required memory for |nva| of length |nvlen| is too large. */ NGHTTP3_EXTERN int nghttp3_conn_submit_trailers(nghttp3_conn *conn, int64_t stream_id, diff --git a/deps/ngtcp2/nghttp3/lib/includes/nghttp3/version.h b/deps/ngtcp2/nghttp3/lib/includes/nghttp3/version.h index adb41c1c7b2d..f362bd4f6ba8 100644 --- a/deps/ngtcp2/nghttp3/lib/includes/nghttp3/version.h +++ b/deps/ngtcp2/nghttp3/lib/includes/nghttp3/version.h @@ -31,7 +31,7 @@ * * Version number of the nghttp3 library release. */ -#define NGHTTP3_VERSION "1.18.0" +#define NGHTTP3_VERSION "1.19.0" /** * @macro @@ -41,6 +41,6 @@ * number, 8 bits for minor and 8 bits for patch. Version 1.2.3 * becomes 0x010203. */ -#define NGHTTP3_VERSION_NUM 0x011200 +#define NGHTTP3_VERSION_NUM 0x011300 #endif /* !defined(NGHTTP3_VERSION_H) */ diff --git a/deps/ngtcp2/nghttp3/lib/nghttp3_balloc.c b/deps/ngtcp2/nghttp3/lib/nghttp3_balloc.c index 436310633349..7750263242ec 100644 --- a/deps/ngtcp2/nghttp3/lib/nghttp3_balloc.c +++ b/deps/ngtcp2/nghttp3/lib/nghttp3_balloc.c @@ -67,7 +67,7 @@ int nghttp3_balloc_get(nghttp3_balloc *balloc, void **pbuf, size_t n) { if (nghttp3_buf_left(&balloc->buf) < n) { p = nghttp3_mem_malloc(balloc->mem, - sizeof(nghttp3_memblock_hd) + 0x8U + balloc->blklen); + sizeof(nghttp3_memblock_hd) + 0xFU + balloc->blklen); if (p == NULL) { return NGHTTP3_ERR_NOMEM; } diff --git a/deps/ngtcp2/nghttp3/lib/nghttp3_buf.c b/deps/ngtcp2/nghttp3/lib/nghttp3_buf.c index 8c33ccdb153f..7c3296cd1efb 100644 --- a/deps/ngtcp2/nghttp3/lib/nghttp3_buf.c +++ b/deps/ngtcp2/nghttp3/lib/nghttp3_buf.c @@ -25,13 +25,15 @@ */ #include "nghttp3_buf.h" -void nghttp3_buf_init(nghttp3_buf *buf) { - buf->begin = buf->end = buf->pos = buf->last = NULL; -} +void nghttp3_buf_init(nghttp3_buf *buf) { *buf = (nghttp3_buf){0}; } void nghttp3_buf_wrap_init(nghttp3_buf *buf, uint8_t *src, size_t len) { - buf->begin = buf->pos = buf->last = src; - buf->end = buf->begin + len; + *buf = (nghttp3_buf){ + .begin = src, + .end = src + len, + .pos = src, + .last = src, + }; } void nghttp3_buf_free(nghttp3_buf *buf, const nghttp3_mem *mem) { diff --git a/deps/ngtcp2/nghttp3/lib/nghttp3_conn.c b/deps/ngtcp2/nghttp3/lib/nghttp3_conn.c index 04b50ac3b632..8b15fb743bd9 100644 --- a/deps/ngtcp2/nghttp3/lib/nghttp3_conn.c +++ b/deps/ngtcp2/nghttp3/lib/nghttp3_conn.c @@ -555,13 +555,14 @@ nghttp3_ssize nghttp3_conn_read_stream2(nghttp3_conn *conn, int64_t stream_id, return 0; } + if (fin) { + stream->flags |= NGHTTP3_STREAM_FLAG_READ_EOF; + } + if (nghttp3_stream_uni(stream_id)) { return nghttp3_conn_read_uni(conn, stream, src, srclen, fin, ts); } - if (fin) { - stream->flags |= NGHTTP3_STREAM_FLAG_READ_EOF; - } return nghttp3_conn_read_bidi(conn, &bidi_nproc, stream, src, srclen, fin, ts); } @@ -1126,6 +1127,13 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn, break; } + /* Apply buffer limits here even if everything is in the input + buffer. */ + if (rstate->left > sizeof(conn->rx.pri_fieldbuf)) { + rstate->state = NGHTTP3_CTRL_STREAM_STATE_IGN_FRAME; + break; + } + conn->rx.pri_fieldbuflen = 0; rstate->state = NGHTTP3_CTRL_STREAM_STATE_PRIORITY_UPDATE; @@ -1141,22 +1149,12 @@ nghttp3_ssize nghttp3_conn_read_control(nghttp3_conn *conn, len = (size_t)nghttp3_min(rstate->left, (uint64_t)(end - p)); assert(len > 0); if (conn->rx.pri_fieldbuflen == 0 && rstate->left == len) { - /* Everything is in the input buffer. Apply same length - limit we impose when buffering the field. */ - if (len > sizeof(conn->rx.pri_fieldbuf)) { - busy = 1; - rstate->state = NGHTTP3_CTRL_STREAM_STATE_IGN_FRAME; - break; - } - + /* Everything is in the input buffer. */ pri_field_value = p; pri_field_valuelen = len; - } else if (len + conn->rx.pri_fieldbuflen > - sizeof(conn->rx.pri_fieldbuf)) { - busy = 1; - rstate->state = NGHTTP3_CTRL_STREAM_STATE_IGN_FRAME; - break; } else { + assert(len + conn->rx.pri_fieldbuflen <= sizeof(conn->rx.pri_fieldbuf)); + memcpy(conn->rx.pri_fieldbuf + conn->rx.pri_fieldbuflen, p, len); conn->rx.pri_fieldbuflen += len; @@ -1975,6 +1973,12 @@ int nghttp3_conn_on_settings_entry_received(nghttp3_conn *conn, break; } +#if SIZE_MAX < UINT64_MAX + if (ent->value > SIZE_MAX) { + return NGHTTP3_ERR_H3_SETTINGS_ERROR; + } +#endif /* SIZE_MAX < UINT64_MAX */ + dest->qpack_max_dtable_capacity = (size_t)ent->value; nghttp3_qpack_encoder_set_max_dtable_capacity(&conn->qenc, @@ -1989,6 +1993,12 @@ int nghttp3_conn_on_settings_entry_received(nghttp3_conn *conn, break; } +#if SIZE_MAX < UINT64_MAX + if (ent->value > SIZE_MAX) { + return NGHTTP3_ERR_H3_SETTINGS_ERROR; + } +#endif /* SIZE_MAX < UINT64_MAX */ + dest->qpack_blocked_streams = (size_t)ent->value; nghttp3_qpack_encoder_set_max_blocked_streams( @@ -2957,6 +2967,8 @@ int nghttp3_conn_set_client_stream_priority(nghttp3_conn *conn, memcpy(buf, data, datalen); } + assert(conn->tx.ctrl); + rv = nghttp3_stream_frq_emplace(conn->tx.ctrl, &fr); if (rv != 0) { nghttp3_mem_free(conn->mem, buf); diff --git a/deps/ngtcp2/nghttp3/lib/nghttp3_frame.c b/deps/ngtcp2/nghttp3/lib/nghttp3_frame.c index 2efba7472c25..aea874fff4dd 100644 --- a/deps/ngtcp2/nghttp3/lib/nghttp3_frame.c +++ b/deps/ngtcp2/nghttp3/lib/nghttp3_frame.c @@ -136,8 +136,8 @@ size_t nghttp3_frame_write_origin_len(uint64_t *ppayloadlen, int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen, const nghttp3_mem *mem) { size_t i; - uint8_t *data = NULL; - size_t buflen = 0; + uint8_t *data; + size_t buflen; nghttp3_nv *p; if (nvlen == 0) { @@ -146,18 +146,32 @@ int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen, return 0; } + if (sizeof(nghttp3_nv) > SIZE_MAX / nvlen) { + return NGHTTP3_ERR_INVALID_ARGUMENT; + } + + buflen = sizeof(nghttp3_nv) * nvlen; + for (i = 0; i < nvlen; ++i) { /* + 1 for null-termination */ if ((nva[i].flags & NGHTTP3_NV_FLAG_NO_COPY_NAME) == 0) { + if (nva[i].namelen == SIZE_MAX || + buflen > SIZE_MAX - nva[i].namelen - 1) { + return NGHTTP3_ERR_INVALID_ARGUMENT; + } + buflen += nva[i].namelen + 1; } if ((nva[i].flags & NGHTTP3_NV_FLAG_NO_COPY_VALUE) == 0) { + if (nva[i].valuelen == SIZE_MAX || + buflen > SIZE_MAX - nva[i].valuelen - 1) { + return NGHTTP3_ERR_INVALID_ARGUMENT; + } + buflen += nva[i].valuelen + 1; } } - buflen += sizeof(nghttp3_nv) * nvlen; - *pnva = nghttp3_mem_malloc(mem, buflen); if (*pnva == NULL) { @@ -169,30 +183,28 @@ int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen, for (i = 0; i < nvlen; ++i) { p->flags = nva[i].flags; + p->namelen = nva[i].namelen; + p->valuelen = nva[i].valuelen; if (nva[i].flags & NGHTTP3_NV_FLAG_NO_COPY_NAME) { p->name = nva[i].name; - p->namelen = nva[i].namelen; } else { if (nva[i].namelen) { memcpy(data, nva[i].name, nva[i].namelen); nghttp3_downcase(data, nva[i].namelen); } p->name = data; - p->namelen = nva[i].namelen; data[p->namelen] = '\0'; data += nva[i].namelen + 1; } if (nva[i].flags & NGHTTP3_NV_FLAG_NO_COPY_VALUE) { p->value = nva[i].value; - p->valuelen = nva[i].valuelen; } else { if (nva[i].valuelen) { memcpy(data, nva[i].value, nva[i].valuelen); } p->value = data; - p->valuelen = nva[i].valuelen; data[p->valuelen] = '\0'; data += nva[i].valuelen + 1; } diff --git a/deps/ngtcp2/nghttp3/lib/nghttp3_frame.h b/deps/ngtcp2/nghttp3/lib/nghttp3_frame.h index 7806cadbcf5f..fee30cb56d7d 100644 --- a/deps/ngtcp2/nghttp3/lib/nghttp3_frame.h +++ b/deps/ngtcp2/nghttp3/lib/nghttp3_frame.h @@ -247,6 +247,8 @@ size_t nghttp3_frame_write_origin_len(uint64_t *ppayloadlen, * * NGHTTP3_ERR_NOMEM * Out of memory. + * NGHTTP3_ERR_INVALID_ARGUMENT + * The required memory for |nva| of length |nvlen| is too large. */ int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen, const nghttp3_mem *mem); diff --git a/deps/ngtcp2/nghttp3/lib/nghttp3_map.c b/deps/ngtcp2/nghttp3/lib/nghttp3_map.c index 7858d4cc3eb1..eae7c4d8dd40 100644 --- a/deps/ngtcp2/nghttp3/lib/nghttp3_map.c +++ b/deps/ngtcp2/nghttp3/lib/nghttp3_map.c @@ -31,6 +31,7 @@ #include #include "nghttp3_conv.h" +#include "nghttp3_macro.h" #define NGHTTP3_INITIAL_HASHBITS 4 @@ -75,18 +76,19 @@ int nghttp3_map_each(const nghttp3_map *map, int (*func)(void *data, void *ptr), return 0; } -/* Hasher from - https://github.com/rust-lang/rustc-hash/blob/dc5c33f1283de2da64d8d7a06401d91aded03ad4/src/lib.rs - to maximize the output's sensitivity to all input bits. */ -#define NGHTTP3_MAP_HASHER 0xF1357AEA2E62A9C5ULL -/* 64-bit Fibonacci hashing constant, Golden Ratio constant, to get - the high bits with the good distribution. */ -#define NGHTTP3_MAP_FIBO 0x9E3779B97F4A7C15ULL +/* 64-bit finalizer (fmix64) from MurmurHash3 to maximize the output's + sensitivity to all input bits. */ +#define NGHTTP3_MAP_HASHER1 0xFF51AFD7ED558CCDULL +#define NGHTTP3_MAP_HASHER2 0xC4CEB9FE1A85EC53ULL static size_t map_index(const nghttp3_map *map, nghttp3_map_key_type key) { - key += map->seed; - key *= NGHTTP3_MAP_HASHER; - return (size_t)((key * NGHTTP3_MAP_FIBO) >> (64 - map->hashbits)); + key ^= map->seed; + key ^= key >> 33; + key *= NGHTTP3_MAP_HASHER1; + key ^= key >> 33; + key *= NGHTTP3_MAP_HASHER2; + key ^= key >> 33; + return (size_t)(key >> (64 - map->hashbits)); } #ifndef WIN32 @@ -108,17 +110,17 @@ void nghttp3_map_print_distance(const nghttp3_map *map) { } idx = map_index(map, map->keys[i]); - fprintf(stderr, "@%zu key=%" PRIu64 " base=%zu distance=%u\n", i, + fprintf(stderr, "@%zu key=%" PRIu64 " base=%zu distance=%zu\n", i, map->keys[i], idx, map->psl[i] - 1); } } #endif /* !defined(WIN32) */ static void map_set_entry(nghttp3_map *map, size_t idx, - nghttp3_map_key_type key, void *data, size_t psl) { + nghttp3_map_key_type key, size_t psl, void *data) { map->keys[idx] = key; + map->psl[idx] = psl; map->data[idx] = data; - map->psl[idx] = (uint8_t)psl; } #define NGHTTP3_SWAP(TYPE, A, B) \ @@ -130,15 +132,15 @@ static void map_set_entry(nghttp3_map *map, size_t idx, } while (0) /* - * map_insert inserts |key| and |data| to |map|, and returns the index - * where the pair is stored if it succeeds. Otherwise, it returns one - * of the following negative error codes: + * map_insert inserts |key| and |data| to |map|. + * + * It returns 0 if it succeeds, or one of the following negative error + * codes: * * NGHTTP3_ERR_INVALID_ARGUMENT * The another data associated to |key| is already present. */ -static nghttp3_ssize map_insert(nghttp3_map *map, nghttp3_map_key_type key, - void *data) { +static int map_insert(nghttp3_map *map, nghttp3_map_key_type key, void *data) { size_t idx = map_index(map, key); size_t mask = ((size_t)1 << map->hashbits) - 1; size_t psl = 1; @@ -148,16 +150,16 @@ static nghttp3_ssize map_insert(nghttp3_map *map, nghttp3_map_key_type key, kpsl = map->psl[idx]; if (kpsl == 0) { - map_set_entry(map, idx, key, data, psl); + map_set_entry(map, idx, key, psl, data); ++map->size; - return (nghttp3_ssize)idx; + return 0; } if (psl > kpsl) { NGHTTP3_SWAP(nghttp3_map_key_type, &key, &map->keys[idx]); + NGHTTP3_SWAP(size_t, &psl, &map->psl[idx]); NGHTTP3_SWAP(void *, &data, &map->data[idx]); - NGHTTP3_SWAP(uint8_t, &psl, &map->psl[idx]); } else if (map->keys[idx] == key) { /* This check ensures that no duplicate keys are inserted. But it is just a waste after first swap or if this function is @@ -179,14 +181,14 @@ static nghttp3_ssize map_insert(nghttp3_map *map, nghttp3_map_key_type key, static int map_resize(nghttp3_map *map, size_t new_hashbits) { size_t i; size_t tablelen; - nghttp3_ssize idx; nghttp3_map new_map = { .mem = map->mem, .seed = map->seed, .hashbits = new_hashbits, }; void *buf; - (void)idx; + int rv; + (void)rv; if (new_hashbits > NGHTTP3_MAP_MAX_HASHBITS) { return NGHTTP3_ERR_NOMEM; @@ -195,16 +197,16 @@ static int map_resize(nghttp3_map *map, size_t new_hashbits) { tablelen = (size_t)1 << new_hashbits; buf = nghttp3_mem_calloc(map->mem, tablelen, - sizeof(nghttp3_map_key_type) + sizeof(void *) + - sizeof(uint8_t)); - if (buf == NULL) { + sizeof(nghttp3_map_key_type) + sizeof(size_t) + + sizeof(void *)); + if (!buf) { return NGHTTP3_ERR_NOMEM; } new_map.keys = buf; - new_map.data = - (void *)((uint8_t *)new_map.keys + tablelen * sizeof(nghttp3_map_key_type)); - new_map.psl = (uint8_t *)new_map.data + tablelen * sizeof(void *); + new_map.psl = (size_t *)(void *)((uint8_t *)new_map.keys + + tablelen * sizeof(nghttp3_map_key_type)); + new_map.data = (void *)((uint8_t *)new_map.psl + tablelen * sizeof(size_t)); if (map->size) { tablelen = (size_t)1 << map->hashbits; @@ -214,31 +216,26 @@ static int map_resize(nghttp3_map *map, size_t new_hashbits) { continue; } - idx = map_insert(&new_map, map->keys[i], map->data[i]); + rv = map_insert(&new_map, map->keys[i], map->data[i]); /* map_insert must not fail because all keys are unique during resize. */ - assert(idx >= 0); + assert(0 == rv); } } nghttp3_mem_free(map->mem, map->keys); map->keys = new_map.keys; - map->data = new_map.data; map->psl = new_map.psl; + map->data = new_map.data; map->hashbits = new_hashbits; return 0; } -/* NGHTTP3_MAX_PSL_RESIZE_THRESH is the maximum psl threshold. If - reached, resize the table. */ -#define NGHTTP3_MAX_PSL_RESIZE_THRESH 128 - int nghttp3_map_insert(nghttp3_map *map, nghttp3_map_key_type key, void *data) { int rv; size_t tablelen; - nghttp3_ssize idx; assert(data); @@ -255,27 +252,9 @@ int nghttp3_map_insert(nghttp3_map *map, nghttp3_map_key_type key, void *data) { if (rv != 0) { return rv; } - - idx = map_insert(map, key, data); - if (idx < 0) { - return (int)idx; - } - - return 0; - } - - idx = map_insert(map, key, data); - if (idx < 0) { - return (int)idx; - } - - /* Resize if psl reaches really large value which is almost - improbable, but just in case. */ - if (map->psl[idx] - 1 < NGHTTP3_MAX_PSL_RESIZE_THRESH) { - return 0; } - return map_resize(map, map->hashbits + 1); + return map_insert(map, key, data); } void *nghttp3_map_find(const nghttp3_map *map, nghttp3_map_key_type key) { @@ -333,7 +312,7 @@ int nghttp3_map_remove(nghttp3_map *map, nghttp3_map_key_type key) { break; } - map_set_entry(map, dest, map->keys[idx], map->data[idx], kpsl - 1); + map_set_entry(map, dest, map->keys[idx], kpsl - 1, map->data[idx]); dest = idx; diff --git a/deps/ngtcp2/nghttp3/lib/nghttp3_map.h b/deps/ngtcp2/nghttp3/lib/nghttp3_map.h index 337f3d63114c..89867fd05468 100644 --- a/deps/ngtcp2/nghttp3/lib/nghttp3_map.h +++ b/deps/ngtcp2/nghttp3/lib/nghttp3_map.h @@ -41,11 +41,11 @@ typedef uint64_t nghttp3_map_key_type; typedef struct nghttp3_map { nghttp3_map_key_type *keys; - void **data; /* psl is the Probe Sequence Length. 0 has special meaning that the element is not stored at i-th position if psl[i] == 0. Because of this, the actual psl value is psl[i] - 1 if psl[i] > 0. */ - uint8_t *psl; + size_t *psl; + void **data; const nghttp3_mem *mem; uint64_t seed; size_t size; diff --git a/deps/ngtcp2/nghttp3/lib/nghttp3_qpack.c b/deps/ngtcp2/nghttp3/lib/nghttp3_qpack.c index 8e950a201d89..2e3d063e1381 100644 --- a/deps/ngtcp2/nghttp3/lib/nghttp3_qpack.c +++ b/deps/ngtcp2/nghttp3/lib/nghttp3_qpack.c @@ -2568,24 +2568,23 @@ nghttp3_ssize nghttp3_qpack_encoder_read_decoder(nghttp3_qpack_encoder *encoder, for (; p != end;) { switch (encoder->state) { case NGHTTP3_QPACK_DS_STATE_OPCODE: - switch ((*p) & 0xC0U) { - case 0x80U: - case 0xC0U: - DEBUGF("qpack::encode: OPCODE_SECTION_ACK\n"); - encoder->opcode = NGHTTP3_QPACK_DS_OPCODE_SECTION_ACK; - encoder->rstate.prefix = 7; + switch ((*p) >> 6) { + case 0x0U: + DEBUGF("qpack::encode: OPCODE_ICNT_INCREMENT\n"); + encoder->opcode = NGHTTP3_QPACK_DS_OPCODE_ICNT_INCREMENT; + encoder->rstate.prefix = 6; break; - case 0x40U: + case 0x1U: DEBUGF("qpack::encode: OPCODE_STREAM_CANCEL\n"); encoder->opcode = NGHTTP3_QPACK_DS_OPCODE_STREAM_CANCEL; encoder->rstate.prefix = 6; break; default: - DEBUGF("qpack::encode: OPCODE_ICNT_INCREMENT\n"); - encoder->opcode = NGHTTP3_QPACK_DS_OPCODE_ICNT_INCREMENT; - encoder->rstate.prefix = 6; + DEBUGF("qpack::encode: OPCODE_SECTION_ACK\n"); + encoder->opcode = NGHTTP3_QPACK_DS_OPCODE_SECTION_ACK; + encoder->rstate.prefix = 7; } encoder->state = NGHTTP3_QPACK_DS_STATE_READ_NUMBER; /* fall through */ @@ -2842,39 +2841,36 @@ nghttp3_ssize nghttp3_qpack_decoder_read_encoder(nghttp3_qpack_decoder *decoder, busy = 0; switch (decoder->state) { case NGHTTP3_QPACK_ES_STATE_OPCODE: - switch ((*p) & 0xE0U) { - case 0x80U: - case 0xA0U: - case 0xC0U: - case 0xE0U: - DEBUGF("qpack::decode: OPCODE_INSERT_INDEXED\n"); - decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_INSERT_INDEXED; - decoder->rstate.dynamic = !((*p) & 0x40U); - decoder->rstate.prefix = 6; + switch ((*p) >> 5) { + case 0x0U: + DEBUGF("qpack::decode: OPCODE_DUPLICATE\n"); + decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_DUPLICATE; + decoder->rstate.dynamic = 1; + decoder->rstate.prefix = 5; decoder->state = NGHTTP3_QPACK_ES_STATE_READ_INDEX; break; - case 0x40U: - case 0x60U: + case 0x1U: + DEBUGF("qpack::decode: OPCODE_SET_DTABLE_TABLE_CAP\n"); + decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_SET_DTABLE_CAP; + decoder->rstate.prefix = 5; + decoder->state = NGHTTP3_QPACK_ES_STATE_READ_INDEX; + + break; + case 0x2U: + case 0x3U: DEBUGF("qpack::decode: OPCODE_INSERT\n"); decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_INSERT; decoder->rstate.dynamic = 0; decoder->rstate.prefix = 5; decoder->state = NGHTTP3_QPACK_ES_STATE_CHECK_NAME_HUFFMAN; - break; - case 0x20U: - DEBUGF("qpack::decode: OPCODE_SET_DTABLE_TABLE_CAP\n"); - decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_SET_DTABLE_CAP; - decoder->rstate.prefix = 5; - decoder->state = NGHTTP3_QPACK_ES_STATE_READ_INDEX; - break; default: - DEBUGF("qpack::decode: OPCODE_DUPLICATE\n"); - decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_DUPLICATE; - decoder->rstate.dynamic = 1; - decoder->rstate.prefix = 5; + DEBUGF("qpack::decode: OPCODE_INSERT_INDEXED\n"); + decoder->opcode = NGHTTP3_QPACK_ES_OPCODE_INSERT_INDEXED; + decoder->rstate.dynamic = !((*p) & 0x40U); + decoder->rstate.prefix = 6; decoder->state = NGHTTP3_QPACK_ES_STATE_READ_INDEX; } break; @@ -2895,6 +2891,12 @@ nghttp3_ssize nghttp3_qpack_decoder_read_encoder(nghttp3_qpack_decoder *decoder, if (decoder->opcode == NGHTTP3_QPACK_ES_OPCODE_SET_DTABLE_CAP) { DEBUGF("qpack::decode: Set dtable capacity to %" PRIu64 "\n", decoder->rstate.left); +#if SIZE_MAX < UINT64_MAX + if (decoder->rstate.left > SIZE_MAX) { + return NGHTTP3_ERR_QPACK_ENCODER_STREAM_ERROR; + } +#endif /* SIZE_MAX < UINT64_MAX */ + rv = nghttp3_qpack_decoder_set_max_dtable_capacity( decoder, (size_t)decoder->rstate.left); if (rv != 0) { @@ -3433,36 +3435,26 @@ nghttp3_qpack_decoder_read_request(nghttp3_qpack_decoder *decoder, case NGHTTP3_QPACK_RS_STATE_OPCODE: assert(sctx->rstate.left == 0); assert(sctx->rstate.shift == 0); - switch ((*p) & 0xF0U) { - case 0x80U: - case 0x90U: - case 0xA0U: - case 0xB0U: - case 0xC0U: - case 0xD0U: - case 0xE0U: - case 0xF0U: - DEBUGF("qpack::decode: OPCODE_INDEXED\n"); - sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED; - sctx->rstate.dynamic = !((*p) & 0x40U); - sctx->rstate.prefix = 6; + switch ((*p) >> 4) { + case 0x0U: + DEBUGF("qpack::decode: OPCODE_INDEXED_NAME_PB\n"); + sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME_PB; + sctx->rstate.never = (*p) & 0x08U; + sctx->rstate.dynamic = 1; + sctx->rstate.prefix = 3; sctx->state = NGHTTP3_QPACK_RS_STATE_READ_INDEX; break; - case 0x40U: - case 0x50U: - case 0x60U: - case 0x70U: - DEBUGF("qpack::decode: OPCODE_INDEXED_NAME\n"); - sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME; - sctx->rstate.never = (*p) & 0x20U; - sctx->rstate.dynamic = !((*p) & 0x10U); + case 0x1U: + DEBUGF("qpack::decode: OPCODE_INDEXED_PB\n"); + sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED_PB; + sctx->rstate.dynamic = 1; sctx->rstate.prefix = 4; sctx->state = NGHTTP3_QPACK_RS_STATE_READ_INDEX; break; - case 0x20U: - case 0x30U: + case 0x2U: + case 0x3U: DEBUGF("qpack::decode: OPCODE_LITERAL\n"); sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_LITERAL; sctx->rstate.never = (*p) & 0x10U; @@ -3471,20 +3463,23 @@ nghttp3_qpack_decoder_read_request(nghttp3_qpack_decoder *decoder, sctx->state = NGHTTP3_QPACK_RS_STATE_CHECK_NAME_HUFFMAN; break; - case 0x10U: - DEBUGF("qpack::decode: OPCODE_INDEXED_PB\n"); - sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED_PB; - sctx->rstate.dynamic = 1; + case 0x4U: + case 0x5U: + case 0x6U: + case 0x7U: + DEBUGF("qpack::decode: OPCODE_INDEXED_NAME\n"); + sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME; + sctx->rstate.never = (*p) & 0x20U; + sctx->rstate.dynamic = !((*p) & 0x10U); sctx->rstate.prefix = 4; sctx->state = NGHTTP3_QPACK_RS_STATE_READ_INDEX; break; default: - DEBUGF("qpack::decode: OPCODE_INDEXED_NAME_PB\n"); - sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED_NAME_PB; - sctx->rstate.never = (*p) & 0x08U; - sctx->rstate.dynamic = 1; - sctx->rstate.prefix = 3; + DEBUGF("qpack::decode: OPCODE_INDEXED\n"); + sctx->opcode = NGHTTP3_QPACK_RS_OPCODE_INDEXED; + sctx->rstate.dynamic = !((*p) & 0x40U); + sctx->rstate.prefix = 6; sctx->state = NGHTTP3_QPACK_RS_STATE_READ_INDEX; } break; diff --git a/deps/ngtcp2/nghttp3/lib/nghttp3_ratelim.c b/deps/ngtcp2/nghttp3/lib/nghttp3_ratelim.c index d7a0267530ca..d6d0738e5de6 100644 --- a/deps/ngtcp2/nghttp3/lib/nghttp3_ratelim.c +++ b/deps/ngtcp2/nghttp3/lib/nghttp3_ratelim.c @@ -32,6 +32,8 @@ void nghttp3_ratelim_init(nghttp3_ratelim *rlim, uint64_t burst, uint64_t rate, nghttp3_tstamp ts) { + burst = nghttp3_min(burst, NGHTTP3_RATELIM_MAX_BURST); + *rlim = (nghttp3_ratelim){ .burst = burst, .rate = rate, @@ -53,19 +55,16 @@ static void ratelim_update(nghttp3_ratelim *rlim, nghttp3_tstamp ts) { d = ts - rlim->ts; rlim->ts = ts; - if (rlim->rate > (UINT64_MAX - rlim->carry) / d) { - gain = UINT64_MAX; - } else { + if (rlim->rate <= (UINT64_MAX - rlim->carry) / d) { gain = rlim->rate * d + rlim->carry; - } + gps = gain / NGHTTP3_SECONDS; - gps = gain / NGHTTP3_SECONDS; + if (gps < rlim->burst && rlim->tokens < rlim->burst - gps) { + rlim->tokens += gps; + rlim->carry = gain % NGHTTP3_SECONDS; - if (gps < rlim->burst && rlim->tokens < rlim->burst - gps) { - rlim->tokens += gps; - rlim->carry = gain % NGHTTP3_SECONDS; - - return; + return; + } } rlim->tokens = rlim->burst; diff --git a/deps/ngtcp2/nghttp3/lib/nghttp3_ratelim.h b/deps/ngtcp2/nghttp3/lib/nghttp3_ratelim.h index 68aab93a61bf..ba8f53788146 100644 --- a/deps/ngtcp2/nghttp3/lib/nghttp3_ratelim.h +++ b/deps/ngtcp2/nghttp3/lib/nghttp3_ratelim.h @@ -33,6 +33,9 @@ #include +/* NGHTTP3_RATELIM_MAX_BURST is the maximum value of the burst. */ +#define NGHTTP3_RATELIM_MAX_BURST (UINT64_MAX / NGHTTP3_SECONDS) + typedef struct nghttp3_ratelim { /* burst is the maximum number of tokens. */ uint64_t burst; @@ -48,8 +51,8 @@ typedef struct nghttp3_ratelim { nghttp3_tstamp ts; } nghttp3_ratelim; -/* nghttp3_ratelim_init initializes |rlim| with the given - parameters. */ +/* nghttp3_ratelim_init initializes |rlim| with the given parameters. + |burst| is clamped to NGHTTP3_RATELIM_MAX_BURST. */ void nghttp3_ratelim_init(nghttp3_ratelim *rlim, uint64_t burst, uint64_t rate, nghttp3_tstamp ts); diff --git a/deps/ngtcp2/nghttp3/lib/nghttp3_stream.h b/deps/ngtcp2/nghttp3/lib/nghttp3_stream.h index d313b1c192b9..07d71573a58f 100644 --- a/deps/ngtcp2/nghttp3/lib/nghttp3_stream.h +++ b/deps/ngtcp2/nghttp3/lib/nghttp3_stream.h @@ -42,8 +42,9 @@ #define NGHTTP3_STREAM_MIN_CHUNK_SIZE 256 /* NGHTTP3_MIN_UNSENT_BYTES is the minimum unsent bytes which is large - enough to fill outgoing single QUIC packet. */ -#define NGHTTP3_MIN_UNSENT_BYTES 4096 + enough to fill outgoing single QUIC packet or TLS record in case of + QMux (Cut 2 bytes for QMux record length). */ +#define NGHTTP3_MIN_UNSENT_BYTES 16382 /* NGHTTP3_STREAM_MIN_WRITELEN is the minimum length of write to cause the stream to reschedule. */ diff --git a/deps/ngtcp2/nghttp3/lib/nghttp3_unreachable.h b/deps/ngtcp2/nghttp3/lib/nghttp3_unreachable.h index c609d7ed72f3..362ceb08c3d2 100644 --- a/deps/ngtcp2/nghttp3/lib/nghttp3_unreachable.h +++ b/deps/ngtcp2/nghttp3/lib/nghttp3_unreachable.h @@ -44,10 +44,10 @@ #ifdef _MSC_VER __declspec(noreturn) #endif /* defined(_MSC_VER) */ - void nghttp3_unreachable_fail(const char *file, int line, const char *func) +void nghttp3_unreachable_fail(const char *file, int line, const char *func) #ifndef _MSC_VER - __attribute__((noreturn)) + __attribute__((noreturn)) #endif /* !defined(_MSC_VER) */ - ; + ; #endif /* !defined(NGHTTP3_UNREACHABLE_H) */ From 3c930d22ea6d2f0e074a644943af97c58ba3b6a8 Mon Sep 17 00:00:00 2001 From: Robert I Nilsson Date: Mon, 12 Oct 2026 17:01:14 +0200 Subject: [PATCH 04/24] doc: document `this` binding in TLS callbacks Document that `this` is bound to the `tls.TLSSocket` instance when `SNICallback` and `ALPNCallback` are invoked. Signed-off-by: Robert I Nilsson PR-URL: https://github.com/nodejs/node/pull/66682 Reviewed-By: Tim Perry --- doc/api/tls.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/api/tls.md b/doc/api/tls.md index e7480b06c16a..032aa4764175 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -2252,7 +2252,8 @@ changes: e.g. `0x05hello0x05world`, where the first byte is the length of the next protocol name. Passing an array is usually much simpler, e.g. `['hello', 'world']`. (Protocols should be ordered by their priority.) - * `ALPNCallback` {Function} If set, this will be called when a + * `ALPNCallback` {Function} If set, this will be called + (with `this` set to the `tls.TLSSocket` instance) when a client opens a connection using the ALPN extension. One argument will be passed to the callback: an object containing `servername` and `protocols` fields, respectively containing the server name from @@ -2282,7 +2283,8 @@ changes: [Session Resumption][] for more information. **Default:** `300`. * `SNICallback(servername, callback)` {Function} A function that will be called if the client supports SNI TLS extension. Two arguments will be - passed when called: `servername` and `callback`. `callback` is an + passed when called: `servername` and `callback`, with `this` set to the + `tls.TLSSocket` instance associated with the connection. `callback` is an error-first callback that takes two optional arguments: `error` and `ctx`. `ctx`, if provided, is a `SecureContext` instance. [`tls.createSecureContext()`][] can be used to get a proper `SecureContext`. From 5aac327abd2a0442311997cd5a0a27a877466663 Mon Sep 17 00:00:00 2001 From: Stewart X Addison <6487691+sxa@users.noreply.github.com> Date: Thu, 12 Nov 2026 14:41:07 +0000 Subject: [PATCH 05/24] test: increase iterations on histogram test after snapshot changes Signed-off-by: Stewart X Addison PR-URL: https://github.com/nodejs/node/pull/67379 Reviewed-By: Philipp Dunkel Reviewed-By: Christian Aurich Zanettini Martins Reviewed-By: Matteo Collina --- test/parallel/test-perf-hooks-histogram-external-memory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-perf-hooks-histogram-external-memory.js b/test/parallel/test-perf-hooks-histogram-external-memory.js index 7e98bd206ec1..9167d0da4bb7 100644 --- a/test/parallel/test-perf-hooks-histogram-external-memory.js +++ b/test/parallel/test-perf-hooks-histogram-external-memory.js @@ -26,7 +26,7 @@ observer.observe({ entryTypes: ['gc'] }); // triggers a major GC if that memory is reported. The GC trigger and finalization // can vary depending on V8 internals, so only check the occurrence of a major GC here. const histogram = createHistogram(); -for (let i = 0; i < 400; i++) histogram.snapshot(); +for (let i = 0; i < 800; i++) histogram.snapshot(); (async () => { // Performance entries for garbage collections are delivered asynchronously. From 8dfdbb540e9871548efb9cb19652eca227fb0d59 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 12 Nov 2026 16:39:25 +0100 Subject: [PATCH 06/24] tools: enable strict mode for yamllint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Treats warnings as errors, so we can detect regressions. Signed-off-by: Antoine du Hamel PR-URL: https://github.com/nodejs/node/pull/67380 Reviewed-By: Luigi Pinca Reviewed-By: Filip Skokan Reviewed-By: Ulises Gascón --- .github/workflows/nix-changes.yml | 2 +- Makefile | 4 +++- test/fixtures/test426/.github/workflows/ci.yml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/nix-changes.yml b/.github/workflows/nix-changes.yml index 713e740e2701..779644689150 100644 --- a/.github/workflows/nix-changes.yml +++ b/.github/workflows/nix-changes.yml @@ -50,7 +50,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: fetch-depth: 2 - persist-credentials: true # We need read access in case we need to fetch in `Compute requisites before change` step + persist-credentials: true # We need read access in case we need to fetch in `Compute requisites before change` step sparse-checkout: | shell.nix tools/nix/ diff --git a/Makefile b/Makefile index fbf6f3f5323a..fa6979120dce 100644 --- a/Makefile +++ b/Makefile @@ -1715,15 +1715,17 @@ endif # python -m pip install yamllint # Try with '--system' if it fails without; the system may have set '--user' lint-yaml-build: ## Build resources needed to lint YAML files. +ifeq ($(YAMLLINT), tools/pip/site-packages/bin/yamllint) $(info Pip installing yamllint on $(shell $(PYTHON) --version)...) $(PYTHON) -m pip install --upgrade -t tools/pip/site-packages yamllint || \ $(PYTHON) -m pip install --upgrade --system -t tools/pip/site-packages yamllint +endif .PHONY: lint-yaml ifneq ("","$(wildcard $(YAMLLINT))") lint-yaml: ## Lint the YAML files with yamllint. $(info Running YAML linter...) - PYTHONPATH=tools/pip $(YAMLLINT) . + PYTHONPATH=tools/pip $(YAMLLINT) --strict . else lint-yaml: $(warning YAML linting with yamllint is not available) diff --git a/test/fixtures/test426/.github/workflows/ci.yml b/test/fixtures/test426/.github/workflows/ci.yml index 72d33dddb54c..0eb2f29f8573 100644 --- a/test/fixtures/test426/.github/workflows/ci.yml +++ b/test/fixtures/test426/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: runs-on: ubuntu-latest permissions: contents: read - id-token: write # for npm trusted publishing + id-token: write # for npm trusted publishing concurrency: group: npm-publish cancel-in-progress: false From e396cb0bb331463c13dce8e7f6c372c8832c95ee Mon Sep 17 00:00:00 2001 From: Manjeet Singh <024manjeetsingh@gmail.com> Date: Fri, 13 Nov 2026 02:37:25 +0530 Subject: [PATCH 07/24] doc: explain fallback arrays in package exports targets The "exports" field type lists `string[]`, but the packages documentation never describes how an array of targets is resolved. Document that items are tried in order, that only invalid targets and unmatched conditions are skipped, and that a missing file does not cause the next item to be tried. Fixes: https://github.com/nodejs/node/issues/58600 Signed-off-by: Manjeet Singh <024manjeetsingh@gmail.com> PR-URL: https://github.com/nodejs/node/pull/67393 Reviewed-By: Jordan Harband Reviewed-By: Jacob Smith --- doc/api/packages.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/doc/api/packages.md b/doc/api/packages.md index 99dc77610bf3..75b0a2b71cab 100644 --- a/doc/api/packages.md +++ b/doc/api/packages.md @@ -782,6 +782,40 @@ a nested condition does not have any mapping it will continue checking the remaining conditions of the parent condition. In this way nested conditions behave analogously to nested JavaScript `if` statements. +### Target fallback arrays + +Anywhere a target is accepted in the [`"exports"`][] or [`"imports"`][] fields, +an array of targets can be used instead. Node.js tries the items in order and +uses the first one that is a valid target. An item is skipped, and the next one +is tried, only when: + +* it is not a valid target, for example a string that does not follow the + [path rules for export targets][], or +* it is a conditions object in which no condition matches. + +Fallback arrays exist for compatibility: a package can list a target that only +some environments or future versions of Node.js treat as valid, followed by one +that all of them support. + +Node.js does not check whether the file a target points to exists. Once an +item is a valid target, it is used and the remaining items are ignored, even if +loading the file then fails because it is missing: + +```json +{ + "exports": { + "./feature": ["./src/feature.js", "./dist/feature.js"] + } +} +``` + +Here `./feature` always resolves to `./src/feature.js`. An array cannot be used +to fall back from a missing file to another file. + +If the array is empty, the subpath is not exported. If every item is an +invalid target, the error for the last item is thrown. The exact behavior is +defined by `PACKAGE_TARGET_RESOLVE` in the [package resolution algorithm][]. + ### Resolving user conditions