@@ -127,9 +127,16 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric(struct DecoderState *ds) {
127
127
128
128
JSUINT64 overflowLimit = LLONG_MAX ;
129
129
130
- if (* (offset ) == '-' ) {
130
+ if (* (offset ) == 'I' ) {
131
+ goto DECODE_INF ;
132
+ } else if (* (offset ) == 'N' ) {
133
+ goto DECODE_NAN ;
134
+ } else if (* (offset ) == '-' ) {
131
135
offset ++ ;
132
136
intNeg = -1 ;
137
+ if (* (offset ) == 'I' ) {
138
+ goto DECODE_INF ;
139
+ }
133
140
overflowLimit = LLONG_MIN ;
134
141
}
135
142
@@ -281,6 +288,48 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_numeric(struct DecoderState *ds) {
281
288
}
282
289
}
283
290
291
+ DECODE_NAN :
292
+ offset ++ ;
293
+ if (* (offset ++ ) != 'a' ) goto SET_NAN_ERROR ;
294
+ if (* (offset ++ ) != 'N' ) goto SET_NAN_ERROR ;
295
+
296
+ ds -> lastType = JT_NULL ;
297
+ ds -> start = offset ;
298
+ return ds -> dec -> newNull (ds -> prv );
299
+
300
+ SET_NAN_ERROR :
301
+ return SetError (ds , -1 , "Unexpected character found when decoding 'NaN'" );
302
+
303
+ DECODE_INF :
304
+ offset ++ ;
305
+ if (* (offset ++ ) != 'n' ) goto SET_INF_ERROR ;
306
+ if (* (offset ++ ) != 'f' ) goto SET_INF_ERROR ;
307
+ if (* (offset ++ ) != 'i' ) goto SET_INF_ERROR ;
308
+ if (* (offset ++ ) != 'n' ) goto SET_INF_ERROR ;
309
+ if (* (offset ++ ) != 'i' ) goto SET_INF_ERROR ;
310
+ if (* (offset ++ ) != 't' ) goto SET_INF_ERROR ;
311
+ if (* (offset ++ ) != 'y' ) goto SET_INF_ERROR ;
312
+
313
+ ds -> start = offset ;
314
+
315
+ if (intNeg == 1 ) {
316
+ ds -> lastType = JT_POS_INF ;
317
+ return ds -> dec -> newPosInf (ds -> prv );
318
+ } else {
319
+ ds -> lastType = JT_NEG_INF ;
320
+ return ds -> dec -> newNegInf (ds -> prv );
321
+ }
322
+
323
+ SET_INF_ERROR :
324
+ if (intNeg == 1 ) {
325
+ const char * msg = "Unexpected character found when decoding 'Infinity'" ;
326
+ return SetError (ds , -1 , msg );
327
+ } else {
328
+ const char * msg = "Unexpected character found when decoding '-Infinity'" ;
329
+ return SetError (ds , -1 , msg );
330
+ }
331
+
332
+
284
333
BREAK_EXP_LOOP :
285
334
// FIXME: Check for arithmetic overflow here
286
335
ds -> lastType = JT_DOUBLE ;
@@ -1070,6 +1119,8 @@ FASTCALL_ATTR JSOBJ FASTCALL_MSVC decode_any(struct DecoderState *ds) {
1070
1119
case '7' :
1071
1120
case '8' :
1072
1121
case '9' :
1122
+ case 'I' :
1123
+ case 'N' :
1073
1124
case '-' :
1074
1125
return decode_numeric (ds );
1075
1126
0 commit comments