From def8e769992332a9373559ecd2058ef4ac8698fa Mon Sep 17 00:00:00 2001 From: James M Snell Date: Tue, 30 Jun 2020 09:35:59 -0700 Subject: [PATCH] quic: fixup set_final_size Ignore subsequent calls to set_final_size unless the new size is more than the previous, in which case, we have us a bug. PR-URL: https://github.com/nodejs/node/pull/34137 Reviewed-By: Anna Henningsen Reviewed-By: David Carlier --- src/quic/node_quic_stream-inl.h | 7 ++++++- src/quic/node_quic_stream.cc | 1 - src/quic/node_quic_stream.h | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/quic/node_quic_stream-inl.h b/src/quic/node_quic_stream-inl.h index 3da0f5fb3b57cf..3dd1fc216d9783 100644 --- a/src/quic/node_quic_stream-inl.h +++ b/src/quic/node_quic_stream-inl.h @@ -35,7 +35,12 @@ void QuicStream::set_flag(int32_t flag, bool on) { } void QuicStream::set_final_size(uint64_t final_size) { - CHECK_EQ(GetStat(&QuicStreamStats::final_size), 0); + // Only set the final size once. + if (is_flag_set(QUICSTREAM_FLAG_FIN)) { + CHECK_LE(final_size, GetStat(&QuicStreamStats::final_size)); + return; + } + set_flag(QUICSTREAM_FLAG_FIN); SetStat(&QuicStreamStats::final_size, final_size); } diff --git a/src/quic/node_quic_stream.cc b/src/quic/node_quic_stream.cc index 7a1054db407f59..ce8cc78a1ec8c5 100644 --- a/src/quic/node_quic_stream.cc +++ b/src/quic/node_quic_stream.cc @@ -355,7 +355,6 @@ void QuicStream::ReceiveData( // When fin != 0, we've received that last chunk of data for this // stream, indicating that the stream will no longer be readable. if (flags & NGTCP2_STREAM_DATA_FLAG_FIN) { - set_flag(QUICSTREAM_FLAG_FIN); set_final_size(offset + datalen); EmitRead(UV_EOF); } diff --git a/src/quic/node_quic_stream.h b/src/quic/node_quic_stream.h index 97174dcb7b925d..d8297f300ba85c 100644 --- a/src/quic/node_quic_stream.h +++ b/src/quic/node_quic_stream.h @@ -256,7 +256,11 @@ class QuicStream : public AsyncWrap, // Specifies the kind of headers currently being processed. inline void set_headers_kind(QuicStreamHeadersKind kind); - // Set the final size for the QuicStream + // Set the final size for the QuicStream. This only works + // the first time it is called. Subsequent calls will be + // ignored unless the subsequent size is greater than the + // prior set size, in which case we have a bug and we'll + // assert. inline void set_final_size(uint64_t final_size); // The final size is the maximum amount of data that has been