Skip to content

Commit b575be5

Browse files
committed
Fix handling of unescaped control characters preceeded by a backslash
1 parent 09d4d88 commit b575be5

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
### Unreleased
44

5+
* Fix handling of unescaped control characters preceeded by a backslash.
6+
57
### 2026-03-18 (2.19.2)
68

79
* Fix a format string injection vulnerability in `JSON.parse(doc, allow_duplicate_key: false)`. `CVE-2026-33210`.

ext/json/ext/parser/parser.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,9 @@ NOINLINE(static) VALUE json_string_unescape(JSON_ParserState *state, JSON_Parser
770770
}
771771
raise_parse_error_at("invalid ASCII control character in string: %s", state, pe - 1);
772772
}
773-
} else if (config->allow_invalid_escape) {
773+
}
774+
775+
if (config->allow_invalid_escape) {
774776
APPEND_CHAR(*pe);
775777
} else {
776778
raise_parse_error_at("invalid escape character in string: %s", state, pe - 1);

test/json/json_parser_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ def test_parse_allowed_control_chars_in_string
183183
end
184184
end
185185

186+
def test_parsse_control_char_and_backslash
187+
backslash_and_control_char = "\\\t"
188+
assert_raise JSON::ParserError do
189+
JSON.parse(%("#{'a' * 30}#{backslash_and_control_char}"), allow_control_characters: true, allow_invalid_escape: false)
190+
end
191+
192+
JSON.parse(%("#{'a' * 30}#{backslash_and_control_char}"), allow_control_characters: true, allow_invalid_escape: true)
193+
end
194+
186195
def test_parse_invalid_escape
187196
assert_raise JSON::ParserError do
188197
parse(%("fo\\o"))

0 commit comments

Comments
 (0)