Harden reporters against formula injection and invalid JSON / input shape (fixes #2299) - #2300
Open
jdymitarai wants to merge 1 commit into
Open
Harden reporters against formula injection and invalid JSON / input shape (fixes #2299)#2300jdymitarai wants to merge 1 commit into
jdymitarai wants to merge 1 commit into
Conversation
…hape (fixes google#2299) This resolves the three defense-in-depth hardening notes raised in google#2299: 1. CSV formula-prefix neutralization: - Neutralize spreadsheet formula prefixes ('=', '+', '-', '@') in CsvEscape by prepending a single quote (') when enclosed in double quotes. - Properly escape embedded double quotes as "" and handle user counter header names with CsvEscape. 2. Full C0 control character escaping in JSON reporter: - Adhere strictly to RFC 8259 Section 7 by escaping all C0 control characters (0x00 to 0x1F) as \u00XX in internal::JsonStrEscape. - Preserves standard two-character escapes (\b, \f, \n, \r, \t, \", \\) and raw UTF-8 multi-byte sequences. 3. Input shape and type diagnostics in gbench tooling: - Add check_benchmark_results() in tools/gbench/util.py to validate JSON artifact structure, benchmark arrays, names, numeric times, and valid time units. - Provide informative diagnostics before processing benchmark comparisons. - Add comprehensive unit tests in tools/gbench/util.py, test/string_util_gtest.cc, and test/reporter_list_gtest.cc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request resolves the three defense-in-depth hardening notes reported in #2299 across the C++ core reporters and the Python tooling:
Neutralize CSV Formula-Prefix Injection (
CSVReporter):internal::CsvEscape, if a field value starts with a formula trigger character (=,+,-, or@), neutralize it by prepending a single-quote (') inside the quoted field (e.g."=CMD"becomes"'=CMD").") as"".CsvEscape.iterations,real_time,cpu_time) remain unquoted raw numbers, avoiding unwanted string coercion.Full C0 Control Character Escaping (
JSONReporter):U+0000throughU+001Fmust be escaped.internal::JsonStrEscapenow escapes any byte< 0x20as\u00XX(e.g. ANSI escape\x1b->\u001b, NUL ->\u0000), preventing strict JSON parsers from rejecting benchmark JSON artifacts containing terminal color codes in skip/error messages.\b,\f,\n,\r,\t,\",\\) and passes UTF-8 multi-byte sequences through unchanged.Input Shape and Type Diagnostics (
tools/gbench/util.py):check_benchmark_results(results, fname)to validate root object shape,context,benchmarkslist, run names, numeric time values, and validtime_unitvalues ({"ns", "us", "ms", "s"}).TypeError,KeyError) when loading corrupted or malformed benchmark output artifacts.Verification & Tests
test/string_util_gtest.cc: Added tests forCsvEscape(formula triggers=+-@, embedded quotes) andJsonStrEscape(full C0 range0x00..0x1F, ANSI escapes, UTF-8 strings). Passed 22/22 tests.test/reporter_list_gtest.cc: Added tests for CSV formula escaping and JSON C0 escaping. Passed 7/7 tests.tools/gbench/util.py: AddedTestCheckBenchmarkResultscovering 9 validation failure and success scenarios.test/string_util_gtest.exe: PASSED (22 tests)test/reporter_list_gtest.exe: PASSED (7 tests)test/reporter_output_test.exe: PASSED (full end-to-end reporter suite)python -m unittest discover -s tools -p "*.py": PASSED (38 tests)AI Usage Disclosure
Per
AGENTS.mdguidelines:Fixes #2299.