Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
79fa8b2f
Commit
79fa8b2f
authored
Dec 12, 2016
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚑
fix to address #389
parent
447e0142
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
2 deletions
+49
-2
json.hpp
src/json.hpp
+16
-1
json.hpp.re2c
src/json.hpp.re2c
+16
-1
unit-regression.cpp
test/src/unit-regression.cpp
+17
-0
No files found.
src/json.hpp
View file @
79fa8b2f
...
@@ -10643,7 +10643,22 @@ basic_json_parser_66:
...
@@ -10643,7 +10643,22 @@ basic_json_parser_66:
}
}
else
if
(
type
==
value_t
::
number_integer
)
else
if
(
type
==
value_t
::
number_integer
)
{
{
result
.
m_value
.
number_integer
=
-
static_cast
<
number_integer_t
>
(
value
);
// invariant: if we parsed a '-', the absolute value is between
// 0 (we allow -0) and max == -INT64_MIN
assert
(
value
>=
0
);
assert
(
value
<=
max
);
if
(
value
==
max
)
{
// we cannot simply negate value (== max == -INT64_MIN),
// see https://github.com/nlohmann/json/issues/389
result
.
m_value
.
number_integer
=
INT64_MIN
;
}
else
{
// all other values can be negated safely
result
.
m_value
.
number_integer
=
-
static_cast
<
number_integer_t
>
(
value
);
}
}
}
else
else
{
{
...
...
src/json.hpp.re2c
View file @
79fa8b2f
...
@@ -9793,7 +9793,22 @@ class basic_json
...
@@ -9793,7 +9793,22 @@ class basic_json
}
}
else if (type == value_t::number_integer)
else if (type == value_t::number_integer)
{
{
result.m_value.number_integer = -static_cast<number_integer_t>(value);
// invariant: if we parsed a '-', the absolute value is between
// 0 (we allow -0) and max == -INT64_MIN
assert(value >= 0);
assert(value <= max);
if (value == max)
{
// we cannot simply negate value (== max == -INT64_MIN),
// see https://github.com/nlohmann/json/issues/389
result.m_value.number_integer = INT64_MIN;
}
else
{
// all other values can be negated safely
result.m_value.number_integer = -static_cast<number_integer_t>(value);
}
}
}
else
else
{
{
...
...
test/src/unit-regression.cpp
View file @
79fa8b2f
...
@@ -516,4 +516,21 @@ TEST_CASE("regression tests")
...
@@ -516,4 +516,21 @@ TEST_CASE("regression tests")
CHECK_THROWS_AS
(
j
<<
ss
,
std
::
invalid_argument
);
CHECK_THROWS_AS
(
j
<<
ss
,
std
::
invalid_argument
);
CHECK_THROWS_WITH
(
j
<<
ss
,
"parse error - unexpected end of input"
);
CHECK_THROWS_WITH
(
j
<<
ss
,
"parse error - unexpected end of input"
);
}
}
SECTION
(
"issue #389 - Integer-overflow (OSS-Fuzz issue 267)"
)
{
// original test case
json
j1
=
json
::
parse
(
"-9223372036854775808"
);
CHECK
(
j1
.
is_number_integer
());
CHECK
(
j1
.
get
<
json
::
number_integer_t
>
()
==
INT64_MIN
);
// edge case (+1; still an integer)
json
j2
=
json
::
parse
(
"-9223372036854775807"
);
CHECK
(
j2
.
is_number_integer
());
CHECK
(
j2
.
get
<
json
::
number_integer_t
>
()
==
INT64_MIN
+
1
);
// edge case (-1; overflow -> floats)
json
j3
=
json
::
parse
(
"-9223372036854775809"
);
CHECK
(
j3
.
is_number_float
());
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment