@@ -1328,6 +1328,8 @@ inline void Http2Session::HandleHeadersFrame(const nghttp2_frame* frame) {
13281328 return ;
13291329
13301330 std::vector<nghttp2_header> headers (stream->move_headers ());
1331+ DecrementCurrentSessionMemory (stream->current_headers_length_ );
1332+ stream->current_headers_length_ = 0 ;
13311333
13321334 Local<String> name_str;
13331335 Local<String> value_str;
@@ -2021,6 +2023,7 @@ Http2Stream::~Http2Stream() {
20212023 if (session_ == nullptr )
20222024 return ;
20232025 DEBUG_HTTP2STREAM (this , " tearing down stream" );
2026+ session_->DecrementCurrentSessionMemory (current_headers_length_);
20242027 session_->RemoveStream (this );
20252028 session_ = nullptr ;
20262029
@@ -2032,6 +2035,7 @@ Http2Stream::~Http2Stream() {
20322035void Http2Stream::StartHeaders (nghttp2_headers_category category) {
20332036 DEBUG_HTTP2STREAM2 (this , " starting headers, category: %d" , id_, category);
20342037 CHECK (!this ->IsDestroyed ());
2038+ session_->DecrementCurrentSessionMemory (current_headers_length_);
20352039 current_headers_length_ = 0 ;
20362040 current_headers_.clear ();
20372041 current_headers_category_ = category;
@@ -2323,10 +2327,6 @@ inline int Http2Stream::DoWrite(WriteWrap* req_wrap,
23232327 return 0 ;
23242328}
23252329
2326- inline size_t GetBufferLength (nghttp2_rcbuf* buf) {
2327- return nghttp2_rcbuf_get_buf (buf).len ;
2328- }
2329-
23302330// Ads a header to the Http2Stream. Note that the header name and value are
23312331// provided using a buffer structure provided by nghttp2 that allows us to
23322332// avoid unnecessary memcpy's. Those buffers are ref counted. The ref count
@@ -2338,7 +2338,12 @@ inline bool Http2Stream::AddHeader(nghttp2_rcbuf* name,
23382338 CHECK (!this ->IsDestroyed ());
23392339 if (this ->statistics_ .first_header == 0 )
23402340 this ->statistics_ .first_header = uv_hrtime ();
2341- size_t length = GetBufferLength (name) + GetBufferLength (value) + 32 ;
2341+ size_t name_len = nghttp2_rcbuf_get_buf (name).len ;
2342+ if (name_len == 0 && !IsReverted (SECURITY_REVERT_CVE_2019_9516)) {
2343+ return true ; // Ignore headers with empty names.
2344+ }
2345+ size_t value_len = nghttp2_rcbuf_get_buf (value).len ;
2346+ size_t length = name_len + value_len + 32 ;
23422347 // A header can only be added if we have not exceeded the maximum number
23432348 // of headers and the session has memory available for it.
23442349 if (!session_->IsAvailableSessionMemory (length) ||
@@ -2354,6 +2359,7 @@ inline bool Http2Stream::AddHeader(nghttp2_rcbuf* name,
23542359 nghttp2_rcbuf_incref (name);
23552360 nghttp2_rcbuf_incref (value);
23562361 current_headers_length_ += length;
2362+ session_->IncrementCurrentSessionMemory (length);
23572363 return true ;
23582364}
23592365
0 commit comments