Skip to content

Commit 350d1c9

Browse files
committed
fix incorrect argument passed to itow for json syntax error
1 parent 366d49c commit 350d1c9

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

lib/Runtime/Library/JSONScanner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace JSON
2727
void __declspec(noreturn) ThrowSyntaxError(int wErr)
2828
{
2929
char16 scanPos[16];
30-
::_itow_s(GetScanPosition(), scanPos, _countof(scanPos) / sizeof(char16), 10);
30+
::_itow_s(GetScanPosition(), scanPos, _countof(scanPos), 10);
3131
Js::JavascriptError::ThrowSyntaxError(scriptContext, wErr, scanPos);
3232
}
3333

test/JSON/jsonerrorbuffer.baseline

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
10000000
2+
SyntaxError: JSON.parse Error: Unexpected input at position:10000000
3+
at Global code (E:\test\json.js:5:1)

test/JSON/jsonerrorbuffer.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
let desiredLength = 10 * 1000 * 1000;
7+
//desiredLength -= 1;
8+
const json = `"${'a'.repeat(desiredLength - 3)}",`; // "aaa...aaa",
9+
print(json.length);
10+
JSON.parse(json);
11+
print('finished');

test/JSON/rlexe.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,10 @@
102102
<files>stackoverflow.js</files>
103103
</default>
104104
</test>
105+
<test>
106+
<default>
107+
<files>jsonerrorbuffer.js</files>
108+
<baseline>jsonerrorbuffer.baseline</baseline>
109+
</default>
110+
</test>
105111
</regress-exe>

0 commit comments

Comments
 (0)