Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
af223d44
Unverified
Commit
af223d44
authored
May 20, 2018
by
Milo Yip
Committed by
GitHub
May 20, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1261 from fmalita/exponent-underflow
Prevent int underflow when parsing exponents
parents
a0910358
8269bc2b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
1 deletion
+11
-1
reader.h
include/rapidjson/reader.h
+10
-1
readertest.cpp
test/unittest/readertest.cpp
+1
-0
No files found.
include/rapidjson/reader.h
View file @
af223d44
...
...
@@ -1632,9 +1632,18 @@ private:
if
(
RAPIDJSON_LIKELY
(
s
.
Peek
()
>=
'0'
&&
s
.
Peek
()
<=
'9'
))
{
exp
=
static_cast
<
int
>
(
s
.
Take
()
-
'0'
);
if
(
expMinus
)
{
// (exp + expFrac) must not underflow int => we're detecting when -exp gets
// dangerously close to INT_MIN (a pessimistic next digit 9 would push it into
// underflow territory):
//
// -(exp * 10 + 9) + expFrac >= INT_MIN
// <=> exp <= (expFrac - INT_MIN - 9) / 10
RAPIDJSON_ASSERT
(
expFrac
<=
0
);
int
maxExp
=
(
expFrac
+
2147483639
)
/
10
;
while
(
RAPIDJSON_LIKELY
(
s
.
Peek
()
>=
'0'
&&
s
.
Peek
()
<=
'9'
))
{
exp
=
exp
*
10
+
static_cast
<
int
>
(
s
.
Take
()
-
'0'
);
if
(
exp
>=
214748364
)
{
// Issue #313: prevent overflow exponent
if
(
RAPIDJSON_UNLIKELY
(
exp
>
maxExp
))
{
while
(
RAPIDJSON_UNLIKELY
(
s
.
Peek
()
>=
'0'
&&
s
.
Peek
()
<=
'9'
))
// Consume the rest of exponent
s
.
Take
();
}
...
...
test/unittest/readertest.cpp
View file @
af223d44
...
...
@@ -242,6 +242,7 @@ static void TestParseDouble() {
TEST_DOUBLE
(
fullPrecision
,
"1e-214748363"
,
0.0
);
// Maximum supported negative exponent
TEST_DOUBLE
(
fullPrecision
,
"1e-214748364"
,
0.0
);
TEST_DOUBLE
(
fullPrecision
,
"1e-21474836311"
,
0.0
);
TEST_DOUBLE
(
fullPrecision
,
"1.00000000001e-2147483638"
,
0.0
);
TEST_DOUBLE
(
fullPrecision
,
"0.017976931348623157e+310"
,
1.7976931348623157e+308
);
// Max double in another form
// Since
...
...
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