Skip to content

Commit

Permalink
Discard optimized containers with negative counts in UBJSON/BJData (n…
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed May 17, 2022
1 parent 6a73920 commit d0ed61e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions include/nlohmann/detail/input/binary_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ class binary_reader
case 'i':
{
std::int8_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number) || number < 0))
{
return false;
}
Expand All @@ -2027,7 +2027,7 @@ class binary_reader
case 'I':
{
std::int16_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number) || number < 0))
{
return false;
}
Expand All @@ -2038,7 +2038,7 @@ class binary_reader
case 'l':
{
std::int32_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number) || number < 0))
{
return false;
}
Expand All @@ -2049,7 +2049,7 @@ class binary_reader
case 'L':
{
std::int64_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number) || number < 0))
{
return false;
}
Expand Down Expand Up @@ -2113,7 +2113,7 @@ class binary_reader
{
return false;
}
if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1)) // return normal array size if 1D row vector
if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1) || std::count(dim.begin(), dim.end(), 0)) // return normal array size if 1D row vector or total length is 0
{
result = dim.at(dim.size() - 1);
return true;
Expand Down
10 changes: 5 additions & 5 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10490,7 +10490,7 @@ class binary_reader
case 'i':
{
std::int8_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number) || number < 0))
{
return false;
}
Expand All @@ -10501,7 +10501,7 @@ class binary_reader
case 'I':
{
std::int16_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number) || number < 0))
{
return false;
}
Expand All @@ -10512,7 +10512,7 @@ class binary_reader
case 'l':
{
std::int32_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number) || number < 0))
{
return false;
}
Expand All @@ -10523,7 +10523,7 @@ class binary_reader
case 'L':
{
std::int64_t number{};
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number)))
if (JSON_HEDLEY_UNLIKELY(!get_number(input_format, number) || number < 0))
{
return false;
}
Expand Down Expand Up @@ -10587,7 +10587,7 @@ class binary_reader
{
return false;
}
if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1)) // return normal array size if 1D row vector
if (dim.size() == 1 || (dim.size() == 2 && dim.at(0) == 1) || std::count(dim.begin(), dim.end(), 0)) // return normal array size if 1D row vector or total length is 0
{
result = dim.at(dim.size() - 1);
return true;
Expand Down

0 comments on commit d0ed61e

Please sign in to comment.