mirror of
https://github.com/nlohmann/json.git
synced 2026-08-06 09:13:18 +00:00
reject out-of-range code points in UTF-32 wide-string input (#5348)
* reject out-of-range code points in UTF-32 wide-string input Signed-off-by: Angadi Yashaswini <angadi@digiscrypt.com> * remove useless cast to char_traits<char>::int_type Signed-off-by: Angadi Yashaswini <angadi@digiscrypt.com> --------- Signed-off-by: Angadi Yashaswini <angadi@digiscrypt.com>
This commit is contained in:
@@ -7348,8 +7348,12 @@ struct wide_string_input_helper<BaseInputAdapter, 4>
|
||||
}
|
||||
else
|
||||
{
|
||||
// unknown character
|
||||
utf8_bytes[0] = static_cast<std::char_traits<char>::int_type>(wc);
|
||||
// A code point above U+10FFFF has no UTF-8 encoding. Passing the
|
||||
// unit through would narrow it to int, where 0xFFFFFFFF becomes
|
||||
// char_traits<char>::eof() and would end the input silently, so
|
||||
// emit a byte that is never valid UTF-8 and let the decoder
|
||||
// reject it.
|
||||
utf8_bytes[0] = 0xFF;
|
||||
utf8_bytes_filled = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user