Skip to content

Commit bd0d806

Browse files
committed
Fix a possible segfault when parsing JSON containing very large strings
Summary: Taken from Seldaek/jsonlint@a3844d4. Test Plan: Ported the test case from Seldaek/jsonlint#25. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D11323
1 parent a95dd1c commit bd0d806

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ insert_final_newline = true
1111
trim_trailing_whitespace = false
1212
insert_final_newline = false
1313

14+
[src/parser/__tests__/json/*.data]
15+
insert_final_newline = false
16+
1417
[src/parser/__tests__/languageguesser/*]
1518
indent_style =
1619

externals/jsonlint/src/Seld/JsonLint/Lexer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class JsonLintLexer
2020
private $rules = array(
2121
0 => '/^\s+/',
2222
1 => '/^-?([0-9]|[1-9][0-9]+)(\.[0-9]+)?([eE][+-]?[0-9]+)?\b/',
23-
2 => '{^"(\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4}|[^\0-\x09\x0a-\x1f\\\\"])*"}',
23+
2 => '{^"(?:\\\\["bfnrt/\\\\]|\\\\u[a-fA-F0-9]{4}|[^\0-\x09\x0a-\x1f\\\\"]+)*"}',
2424
3 => '/^\{/',
2525
4 => '/^\}/',
2626
5 => '/^\[/',

src/parser/__tests__/PhutilJSONParserTestCase.php

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ public function testValidJSON() {
2222
'{"test":"http:\/\/foo\\\\zomg"}'
2323
=> array('test' => 'http://foo\\zomg'),
2424
'["http:\/\/foo\\\\zomg"]' => array('http://foo\\zomg'),
25+
Filesystem::readFile(dirname(__FILE__).'/json/base64.json') => array(
26+
'action' => 'candidate.create',
27+
'actionId' => '80653a26cc46357ff79ff83b47e27c3cb7a668bd',
28+
'params' => array(
29+
'attachments' => array(
30+
Filesystem::readFile(dirname(__FILE__).'/json/base64.data'),
31+
),
32+
),
33+
),
2534
);
2635

2736
foreach ($tests as $input => $expect) {

src/parser/__tests__/json/base64.data

+1
Large diffs are not rendered by default.

src/parser/__tests__/json/base64.json

+1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)