Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ template:
- fixed `is_homogeneous()` overloads with `first_nonmatch` outparam being broken in optimized builds (#231) (@Forbinn)
- fixed unclear error message when parsing integers that would overflow (#224) (@chrimbo)
- fixed CMake `install` target installing `meson.build` files (#236) (@JWCS)
- lowered `TOML_MAX_NESTED_VALUES` default from 256 to 128 to prevent stack overflow on deeply nested arrays/inline tables in sanitizer builds (@danielbodorin)

## v3.4.0

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's '[
- **[@bjadamson](https://github.com/bjadamson)** - Reported some bugs and helped design a new feature
- **[@bobfang1992](https://github.com/bobfang1992)** - Reported a bug and created a [wrapper in python](https://github.com/bobfang1992/pytomlpp)
- **[@capuanob](https://github.com/capuanob)** - Integrated this project into OSSFuzz
- **[@danielbodorin](https://github.com/danielbodorin)** - Fixed stack overflow from deeply nested arrays/inline tables
- **[@GiulioRomualdi](https://github.com/GiulioRomualdi)** - Added cmake+meson support
- **[@jonestristand](https://github.com/jonestristand)** - Designed and implemented the `toml::path`s feature
- **[@kcsaul](https://github.com/kcsaul)** - Fixed a bug
Expand Down
6 changes: 4 additions & 2 deletions include/toml++/impl/preprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1177,9 +1177,11 @@
#endif

#ifndef TOML_MAX_NESTED_VALUES
#define TOML_MAX_NESTED_VALUES 256
#define TOML_MAX_NESTED_VALUES 128
// this refers to the depth of nested values, e.g. inline tables and arrays.
// 256 is crazy high! if you're hitting this limit with real input, TOML is probably the wrong tool for the job...
// 128 is very generous; real TOML files rarely exceed single-digit nesting.
// keep this value low enough to avoid stack overflows in sanitizer-instrumented builds
// where each recursion cycle may consume ~3KB of stack.
#endif

#ifndef TOML_MAX_DOTTED_KEYS_DEPTH
Expand Down
12 changes: 12 additions & 0 deletions tests/user_feedback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,18 @@ b = []
constexpr auto start = "fl =[ "sv;
memcpy(s.data(), start.data(), start.length());
parsing_should_fail(FILE_LINE_ARGS, std::string_view{ s });

// deeply nested inline tables should also fail gracefully, not stack overflow
{
// build: fl = {a={a={a={a=...{a=1}...}}}
std::string nested_tables = "fl = ";
for (size_t i = 0; i < 2048; i++)
nested_tables += "{a=";
nested_tables += "1";
for (size_t i = 0; i < 2048; i++)
nested_tables += "}";
parsing_should_fail(FILE_LINE_ARGS, std::string_view{ nested_tables });
}
}

SECTION("tomlplusplus/issues/112") // https://github.com/marzer/tomlplusplus/issues/112
Expand Down
6 changes: 4 additions & 2 deletions toml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1086,9 +1086,11 @@
#endif

#ifndef TOML_MAX_NESTED_VALUES
#define TOML_MAX_NESTED_VALUES 256
#define TOML_MAX_NESTED_VALUES 128
// this refers to the depth of nested values, e.g. inline tables and arrays.
// 256 is crazy high! if you're hitting this limit with real input, TOML is probably the wrong tool for the job...
// 128 is very generous; real TOML files rarely exceed single-digit nesting.
// keep this value low enough to avoid stack overflows in sanitizer-instrumented builds
// where each recursion cycle may consume ~3KB of stack.
#endif

#ifndef TOML_MAX_DOTTED_KEYS_DEPTH
Expand Down
Loading