Skip to content

Commit b421086

Browse files
committed
fix(evaluate): error for non u32-bit integer used for indexing arrays
1 parent 5735e0b commit b421086

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/evaluate/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ const evaluate = (
106106
});
107107
}
108108

109-
if (
110-
referenceToken.length > MAX_SAFE_INTEGER.length ||
111-
(referenceToken.length === MAX_SAFE_INTEGER.length && referenceToken > MAX_SAFE_INTEGER)
112-
) {
113-
const message = `Invalid array index "${referenceToken}" at position ${referenceTokenPosition} in "${jsonPointer}": must be a non-negative integer within the I-JSON safe integer range (0 to 2^53 - 1)`;
109+
const index = Number(referenceToken);
110+
const indexUint32 = index >>> 0;
111+
112+
if (strictArrays && index !== indexUint32) {
113+
const message = `Invalid array index "${referenceToken}" at position ${referenceTokenPosition} in "${jsonPointer}": index must be an unsigned 32-bit integer`;
114114

115115
tracer?.step({
116116
referenceToken,
@@ -129,8 +129,7 @@ const evaluate = (
129129
});
130130
}
131131

132-
const index = Number(referenceToken);
133-
if (index >= realm.sizeOf(current) && strictArrays) {
132+
if (strictArrays && index >= realm.sizeOf(current)) {
134133
const message = `Invalid array index "${index}" at position ${referenceTokenPosition} in "${jsonPointer}": out of bounds`;
135134

136135
tracer?.step({

test/evaluate/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('evaluate', function () {
108108
assert.throws(
109109
() => evaluate(data, '/foo/9007199254740992'),
110110
JSONPointerIndexError,
111-
/I-JSON safe integer range \(0 to 2\^53 - 1\)/,
111+
/must be an unsigned 32-bit integer/,
112112
);
113113
});
114114

0 commit comments

Comments
 (0)