Skip to content

Commit aff8ad0

Browse files
committed
Limit RapidJSON Int/Uint to 32-bit signed values per GraphQL spec
1 parent 2a2a0b8 commit aff8ad0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

JSONResponse.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <rapidjson/reader.h>
1414

1515
#include <stack>
16+
#include <limits>
17+
#include <stdexcept>
1618

1719
namespace facebook {
1820
namespace graphql {
@@ -141,6 +143,8 @@ struct ResponseHandler
141143

142144
bool Int(int i)
143145
{
146+
// https://facebook.github.io/graphql/June2018/#sec-Int
147+
static_assert(sizeof(i) == 4, "GraphQL only supports 32-bit signed integers");
144148
auto value = Value(Type::Int);
145149

146150
value.set<IntType>(std::move(i));
@@ -150,17 +154,24 @@ struct ResponseHandler
150154

151155
bool Uint(unsigned int i)
152156
{
157+
if (i > static_cast<unsigned int>(std::numeric_limits<int>::max()))
158+
{
159+
// https://facebook.github.io/graphql/June2018/#sec-Int
160+
throw std::overflow_error("GraphQL only supports 32-bit signed integers");
161+
}
153162
return Int(static_cast<int>(i));
154163
}
155164

156-
bool Int64(int64_t i)
165+
bool Int64(int64_t /*i*/)
157166
{
158-
return Int(static_cast<int>(i));
167+
// https://facebook.github.io/graphql/June2018/#sec-Int
168+
throw std::overflow_error("GraphQL only supports 32-bit signed integers");
159169
}
160170

161-
bool Uint64(uint64_t i)
171+
bool Uint64(uint64_t /*i*/)
162172
{
163-
return Int(static_cast<int>(i));
173+
// https://facebook.github.io/graphql/June2018/#sec-Int
174+
throw std::overflow_error("GraphQL only supports 32-bit signed integers");
164175
}
165176

166177
bool Double(double d)

0 commit comments

Comments
 (0)