From e3639d2bbcc0fbab50260ebc9c7f73e32bc910b9 Mon Sep 17 00:00:00 2001 From: Chris White Date: Sat, 14 Jan 2023 18:09:05 -0500 Subject: [PATCH 1/2] fix: parse_literal_string() properly issues invalid-utf8 errors When creating the inner iterator, make sure it points into the same vector as the outer iterator. Otherwise, attempts to reset the iterator wind up causing it to read out-of-bounds. Fixes #199. --- toml/parser.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/toml/parser.hpp b/toml/parser.hpp index 590cb2a..8da4618 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -664,7 +664,8 @@ parse_literal_string(location& loc) const auto first = loc.iter(); if(const auto token = lex_literal_string::invoke(loc)) { - location inner_loc(loc.name(), token.unwrap().str()); + auto inner_loc = loc; + inner_loc.reset(first); const auto open = lex_apostrophe::invoke(inner_loc); if(!open) From a2f884b11e216d338ac0bcee10922ac893ad8638 Mon Sep 17 00:00:00 2001 From: Chris White Date: Sat, 14 Jan 2023 18:12:03 -0500 Subject: [PATCH 2/2] fix: parse_ml_literal_string() properly issues invalid-utf8 errors Fix the same out-of-bounds read as in parse_literal_string(). --- toml/parser.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/toml/parser.hpp b/toml/parser.hpp index 8da4618..de54ebf 100644 --- a/toml/parser.hpp +++ b/toml/parser.hpp @@ -588,7 +588,8 @@ parse_ml_literal_string(location& loc) const auto first = loc.iter(); if(const auto token = lex_ml_literal_string::invoke(loc)) { - location inner_loc(loc.name(), token.unwrap().str()); + auto inner_loc = loc; + inner_loc.reset(first); const auto open = lex_ml_literal_string_open::invoke(inner_loc); if(!open)