1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-28 12:02:00 +03:00

BJData dimension length can not be string_t::npos, fix #3541 (#3543)

* BJData dimension length can not be string_t::npos, fix #3541

* handle error messages on 32bit machine

* add explanation to why size can not be string_t::npos

* add test cases to 32bit unit test

Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
This commit is contained in:
Qianqian Fang
2022-06-18 13:12:22 -04:00
committed by GitHub
parent f6acdbec2c
commit 13730235f2
4 changed files with 29 additions and 2 deletions

View File

@ -10879,7 +10879,7 @@ class binary_reader
for (auto i : dim)
{
result *= i;
if (result == 0) // because dim elements shall not have zeros, result = 0 means overflow happened
if (result == 0 || result == string_t::npos) // because dim elements shall not have zeros, result = 0 means overflow happened; it also can't be string_t::npos as it is used to initialize size in get_ubjson_size_type()
{
return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, exception_message(input_format, "excessive ndarray size caused overflow", "size"), nullptr));
}