Skip to content

Commit a378e34

Browse files
haoliukChromium LUCI CQ
authored andcommitted
Fix Resource Timing Encoded Body Size overflow.
The existing 'encoded_body_length' in url_response_head.mojom is default to -1. In some cases, this default value is not overwritten and is propagated all the way to JS code and caused number overflow. See details in the last comments of crbug.com/1324812. This CL wraps the `encoded_body_length` without default value into a struct which is made optional. This way, the case it is not set and it is set to 0 and when it is not set, 0 would be used explicitly in the downstream code. Also the type of the field is changed into uint64_t to align with the V8 binding. And because uint64_t and int64 has different range, so variables passed from and into the mojom field also changed their types. Most of files touched are just of this change. Bug: 1336219,1324812 Change-Id: I67f7bd3e47e4f71f719bab9b56cfaa9d388c6f7a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4126836 Reviewed-by: danakj <danakj@chromium.org> Commit-Queue: Hao Liu <haoliuk@chromium.org> Reviewed-by: Yoav Weiss <yoavweiss@chromium.org> Reviewed-by: Matt Menke <mmenke@chromium.org> Reviewed-by: Nasko Oskov <nasko@chromium.org> Cr-Commit-Position: refs/heads/main@{#1091612}
1 parent c0d24bb commit a378e34

29 files changed

Lines changed: 66 additions & 41 deletions

content/browser/devtools/devtools_url_loader_interceptor.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "services/network/public/cpp/resource_request_body.h"
4242
#include "services/network/public/cpp/url_loader_completion_status.h"
4343
#include "services/network/public/mojom/early_hints.mojom.h"
44+
#include "services/network/public/mojom/encoded_body_length.mojom-forward.h"
45+
#include "services/network/public/mojom/encoded_body_length.mojom.h"
4446
#include "services/network/public/mojom/network_context.mojom.h"
4547
#include "services/network/public/mojom/url_loader.mojom.h"
4648
#include "third_party/blink/public/platform/resource_request_blocked_reason.h"
@@ -1220,7 +1222,7 @@ Response InterceptionJob::ProcessResponseOverride(
12201222
size_t headers_size = head->headers->raw_headers().size();
12211223
head->content_length = body_size;
12221224
head->encoded_data_length = headers_size;
1223-
head->encoded_body_length = 0;
1225+
head->encoded_body_length = network::mojom::EncodedBodyLength::New(0u);
12241226
head->request_start = start_ticks_;
12251227
head->response_start = now_ticks;
12261228

content/public/test/render_view_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class FakeWebURLLoader : public blink::WebURLLoader {
117117
absl::optional<blink::WebURLError>&,
118118
blink::WebData&,
119119
int64_t&,
120-
int64_t&,
120+
uint64_t&,
121121
blink::WebBlobInfo&,
122122
std::unique_ptr<blink::ResourceLoadInfoNotifierWrapper>) override {
123123
client->DidFail(blink::WebURLError(kFailureReason, request->url),

services/network/public/mojom/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ mojom("url_loader_base") {
342342
"data_pipe_getter.mojom",
343343
"devtools_observer.mojom",
344344
"early_hints.mojom",
345+
"encoded_body_length.mojom",
345346
"fetch_api.mojom",
346347
"http_raw_headers.mojom",
347348
"http_request_headers.mojom",
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2023 The Chromium Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
module network.mojom;
6+
7+
// This struct contains a encoded body length which is of type unsign long and
8+
// is used as an optional value.
9+
struct EncodedBodyLength {
10+
uint64 value;
11+
};

services/network/public/mojom/url_response_head.mojom

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module network.mojom;
77
import "mojo/public/mojom/base/time.mojom";
88
import "mojo/public/mojom/base/unguessable_token.mojom";
99
import "services/network/public/mojom/alternate_protocol_usage.mojom";
10+
import "services/network/public/mojom/encoded_body_length.mojom";
1011
import "services/network/public/mojom/fetch_api.mojom";
1112
import "services/network/public/mojom/ip_address_space.mojom";
1213
import "services/network/public/mojom/ip_endpoint.mojom";
@@ -55,9 +56,9 @@ struct URLResponseHead {
5556
// no data, contains -1.
5657
int64 encoded_data_length = -1;
5758

58-
// Length of the response body data before decompression. -1 unless the body
59-
// has been read to the end.
60-
int64 encoded_body_length = -1;
59+
// Length of the response body data before decompression. It is null unless
60+
// the body has been read to the end.
61+
network.mojom.EncodedBodyLength? encoded_body_length;
6162

6263
// True if the request accessed the network in the process of retrieving data.
6364
bool network_accessed = false;

third_party/blink/public/platform/internet_disconnected_web_url_loader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class InternetDisconnectedWebURLLoader final : public WebURLLoader {
5555
absl::optional<WebURLError>&,
5656
WebData&,
5757
int64_t& encoded_data_length,
58-
int64_t& encoded_body_length,
58+
uint64_t& encoded_body_length,
5959
WebBlobInfo& downloaded_blob,
6060
std::unique_ptr<blink::ResourceLoadInfoNotifierWrapper>
6161
resource_load_info_notifier_wrapper) override;

third_party/blink/public/platform/web_url_loader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class BLINK_PLATFORM_EXPORT WebURLLoader {
109109
absl::optional<WebURLError>& error,
110110
WebData& data,
111111
int64_t& encoded_data_length,
112-
int64_t& encoded_body_length,
112+
uint64_t& encoded_body_length,
113113
WebBlobInfo& downloaded_blob,
114114
std::unique_ptr<ResourceLoadInfoNotifierWrapper>
115115
resource_load_info_notifier_wrapper);

third_party/blink/public/platform/web_url_loader_client.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class BLINK_PLATFORM_EXPORT WebURLLoaderClient {
113113
virtual void DidFinishLoading(
114114
base::TimeTicks finish_time,
115115
int64_t total_encoded_data_length,
116-
int64_t total_encoded_body_length,
116+
uint64_t total_encoded_body_length,
117117
int64_t total_decoded_body_length,
118118
bool should_report_corb_blocking,
119119
absl::optional<bool> pervasive_payload_requested = absl::nullopt) {}
@@ -124,7 +124,7 @@ class BLINK_PLATFORM_EXPORT WebURLLoaderClient {
124124
virtual void DidFail(const WebURLError&,
125125
base::TimeTicks finish_time,
126126
int64_t total_encoded_data_length,
127-
int64_t total_encoded_body_length,
127+
uint64_t total_encoded_body_length,
128128
int64_t total_decoded_body_length) {}
129129

130130
// Value passed to DidFinishLoading when total encoded data length isn't

third_party/blink/public/platform/web_url_response.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ class BLINK_PLATFORM_EXPORT WebURLResponse {
247247

248248
// Original size of the response body before decompression.
249249
int64_t EncodedBodyLength() const;
250-
void SetEncodedBodyLength(int64_t);
250+
void SetEncodedBodyLength(uint64_t);
251251

252252
void SetIsSignedExchangeInnerResponse(bool);
253253
void SetWasInPrefetchCache(bool);

third_party/blink/renderer/bindings/core/v8/script_streamer_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class NoopLoaderFactory final : public ResourceFetcher::LoaderFactory {
109109
absl::optional<WebURLError>&,
110110
WebData&,
111111
int64_t& encoded_data_length,
112-
int64_t& encoded_body_length,
112+
uint64_t& encoded_body_length,
113113
WebBlobInfo& downloaded_blob,
114114
std::unique_ptr<blink::ResourceLoadInfoNotifierWrapper>
115115
resource_load_info_notifier_wrapper) override {

0 commit comments

Comments
 (0)