Skip to content

Commit 9870294

Browse files
davidbenCommit Bot
authored and
Commit Bot
committed
Bound output in net_gzip_source_stream_fuzzer
Gzip has a maximum compression ratio of 1032x. While, strictly speaking, linear, this means the fuzzer will often get stuck. Stop reading at a more modest compression ratio of 10x, or 2 MiB, whichever is larger. Bug: 921075 Change-Id: I529632762b66e4fae0bbdce8ea6d746d98cc2d99 Reviewed-on: https://chromium-review.googlesource.com/c/1483873 Commit-Queue: David Benjamin <davidben@chromium.org> Auto-Submit: David Benjamin <davidben@chromium.org> Reviewed-by: Matt Menke <mmenke@chromium.org> Cr-Commit-Position: refs/heads/master@{#634852}
1 parent 5b1f5e4 commit 9870294

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

net/filter/gzip_source_stream_fuzzer.cc

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "net/filter/gzip_source_stream.h"
66

7+
#include <algorithm>
8+
79
#include "base/logging.h"
810
#include "base/memory/ref_counted.h"
911
#include "base/test/fuzzed_data_provider.h"
@@ -20,12 +22,20 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
2022
std::unique_ptr<net::FuzzedSourceStream> fuzzed_source_stream(
2123
new net::FuzzedSourceStream(&data_provider));
2224

25+
// Gzip has a maximum compression ratio of 1032x. While, strictly speaking,
26+
// linear, this means the fuzzer will often get stuck. Stop reading at a more
27+
// modest compression ratio of 10x, or 2 MiB, whichever is larger. See
28+
// https://crbug.com/921075.
29+
size_t max_output =
30+
std::max(10u * size, static_cast<size_t>(2 * 1024 * 1024));
31+
2332
const net::SourceStream::SourceType kGzipTypes[] = {
2433
net::SourceStream::TYPE_GZIP, net::SourceStream::TYPE_DEFLATE};
2534
net::SourceStream::SourceType type =
2635
data_provider.PickValueInArray(kGzipTypes);
2736
std::unique_ptr<net::GzipSourceStream> gzip_stream =
2837
net::GzipSourceStream::Create(std::move(fuzzed_source_stream), type);
38+
size_t bytes_read = 0;
2939
while (true) {
3040
scoped_refptr<net::IOBufferWithSize> io_buffer =
3141
base::MakeRefCounted<net::IOBufferWithSize>(64);
@@ -34,7 +44,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
3444
// Releasing the pointer to IOBuffer immediately is more likely to lead to a
3545
// use-after-free.
3646
io_buffer = nullptr;
37-
if (callback.GetResult(result) <= 0)
47+
result = callback.GetResult(result);
48+
if (result <= 0)
49+
break;
50+
bytes_read += static_cast<size_t>(result);
51+
if (bytes_read >= max_output)
3852
break;
3953
}
4054

0 commit comments

Comments
 (0)