-
Notifications
You must be signed in to change notification settings - Fork 5.5k
stats: Avoid asserts in fuzz-tests by eliminating arbitrary length limits, using the new MemBlock wrapper for memcpy #8779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
5d40fc4
8f9ab93
beb4684
d143365
5ef1a49
c425551
f680ccc
9fee9f5
184fbed
6ac3dee
9c62a9e
4482ca7
14220bb
4d345d0
5b6f0db
70ffe33
9f1eae7
cf33e18
14b8740
eb6eb51
6d4b8bc
cf71f0b
256a857
cb17d28
7b3150e
c4ddd4a
c728651
4824977
3c9b184
5f4ea86
64c0af4
06e3fbc
b2131df
a281e28
cd98dd2
cf7b451
8069e89
9ae8144
922a860
6dcc218
006b5c7
aa70e5e
9033ac6
d19d722
ae1da1b
bc9871e
ae0b1dd
f4ef7c6
3edfac7
4f5be6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,26 +5,42 @@ | |
| #include "test/fuzz/fuzz_runner.h" | ||
| #include "test/fuzz/utility.h" | ||
|
|
||
| #include "absl/strings/match.h" | ||
| #include "absl/strings/string_view.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Stats { | ||
| namespace Fuzz { | ||
|
|
||
| // Adds a stat-name to the symbol table, discarding it if it ends in ".", and | ||
| // splitting it in two if it's too long (64k bytes). | ||
| // | ||
| // The actual requirement for StatName allows up to 64k "."-separated segments | ||
| // of 64k, but it's simpler to just limit the whole string. I don't think | ||
| // there's that much value in using strings larger than 64k. | ||
| void addSymbol(StatNamePool& pool, SymbolTable& symbol_table, absl::string_view str) { | ||
| while (absl::EndsWith(str, ".")) { | ||
| str.remove_suffix(1); | ||
| } | ||
|
|
||
| if (str.size() >= StatNameMaxSize) { | ||
| size_t halfway = str.size() / 2; | ||
| addSymbol(pool, symbol_table, str.substr(0, halfway)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to have this kind of smart logic; if you just cap the string at
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm changing the symbol-table impl to simply not have this limit, which should simplify fuzzing. It works I think but still not quite ready for review. Will ping again when ready.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is ready for review now. |
||
| addSymbol(pool, symbol_table, str.substr(halfway)); | ||
| } else if (!str.empty()) { | ||
| StatName stat_name = pool.add(str); | ||
| FUZZ_ASSERT(str == symbol_table.toString(stat_name)); | ||
| } | ||
| } | ||
|
|
||
| // Fuzzer for symbol tables. | ||
| DEFINE_FUZZER(const uint8_t* buf, size_t len) { | ||
| FuzzedDataProvider provider(buf, len); | ||
| SymbolTableImpl symbol_table; | ||
| StatNamePool pool(symbol_table); | ||
|
|
||
| while (provider.remaining_bytes() != 0) { | ||
| std::string next_data = provider.ConsumeRandomLengthString(provider.remaining_bytes()); | ||
|
|
||
| // ending with a "." is not considered legal, so just skip. | ||
| if (!next_data.empty() && next_data[next_data.size() - 1] == '.') { | ||
| continue; | ||
| } | ||
|
|
||
| StatName stat_name = pool.add(next_data); | ||
| FUZZ_ASSERT(next_data == symbol_table.toString(stat_name)); | ||
| addSymbol(pool, symbol_table, provider.ConsumeRandomLengthString(provider.remaining_bytes())); | ||
|
jmarantz marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.