Reject JSON references that index into empty arrays

This commit is contained in:
Tristan Penman 2021-01-17 13:34:52 +11:00
parent 3621f98d43
commit fba5a9e8a7

View File

@ -193,9 +193,11 @@ inline AdapterType resolveJsonPointer(
// Fragment must be non-negative integer
const uint64_t index = std::stoul(referenceToken);
typedef typename AdapterType::Array Array;
typename Array::const_iterator itr = node.asArray().begin();
const Array arr = node.asArray();
typename Array::const_iterator itr = arr.begin();
const uint64_t arrSize = arr.size();
if (index > node.asArray().size() - 1) {
if (arrSize == 0 || index > arrSize - 1) {
throwRuntimeError("Expected reference token to identify "
"an element in the current array, but array index is "
"out of bounds; actual token: " + referenceToken);