Skip to content

Commit ff38436

Browse files
committed
[MERGE #5984 @MikeHolman] fix incorrect argument passed to itow for json syntax error
Merge pull request #5984 from MikeHolman:jsonerrorbuffer Fixes #5975
2 parents 3332c6f + 9cb9f7d commit ff38436

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-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.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
let threw = false;
8+
const json = `"${'a'.repeat(desiredLength - 3)}",`;
9+
try {
10+
JSON.parse(json);
11+
} catch(e) {
12+
threw = true;
13+
}
14+
print(threw ? "Pass" : "Fail");

test/JSON/rlexe.xml

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

0 commit comments

Comments
 (0)