Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Maarch
maarchRM
Commits
8170070b
Verified
Commit
8170070b
authored
Mar 03, 2020
by
Cyril Vazquez
Browse files
Unsecpae chunklen + 1
parent
724134ee
Pipeline
#7134
canceled with stages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
core/Encoding/JsonTokenizer.php
View file @
8170070b
...
...
@@ -220,11 +220,13 @@ class JsonTokenizer
fwrite
(
$buffer
,
$this
->
unescape
(
$tail
));
fseek
(
$this
->
stream
,
(
-
$length
+
$end
+
1
),
SEEK_CUR
);
rewind
(
$buffer
);
$out
=
$this
->
unescapeStream
(
$buffer
,
$this
->
threshold
);
if
(
$size
<
$this
->
threshold
)
{
return
$this
->
unescape
(
stream_get_contents
(
$
buffer
)
);
return
stream_get_contents
(
$
out
);
}
return
$
buffer
;
return
$
out
;
}
fwrite
(
$buffer
,
$this
->
unescape
(
$chunk
));
...
...
@@ -234,6 +236,8 @@ class JsonTokenizer
return
$buffer
;
}
/**
* @param $char
* @return string
...
...
@@ -300,13 +304,31 @@ class JsonTokenizer
return
end
(
$this
->
context
);
}
/**
* Unsescape a stream contents
*/
protected
function
unescapeStream
(
$stream
)
{
$out
=
fopen
(
'php://temp'
,
'w+'
);
do
{
// Add 1 to chunk length to prevent end of chunk escape chars
$chunk
=
fread
(
$stream
,
$this
->
threshold
+
1
);
fwrite
(
$out
,
$this
->
unescape
(
$chunk
));
}
while
(
$chunk
);
rewind
(
$out
);
rewind
(
$stream
);
return
$out
;
}
/**
* Unescape string or chunk
*/
protected
function
unescape
(
$string
)
{
$escaped
=
array
(
'\\\\'
,
'\\/'
,
'\\"'
);
//
, "\\n", "\\r", "\\t", "\\f", "\\b");
$unescaped
=
array
(
'\\'
,
'/'
,
'"'
);
//
, "\n", "\r", "\t", "\x08", "\x0c");
$escaped
=
array
(
'\\\\'
,
'\\/'
,
'\\"'
,
"
\\
n"
,
"
\\
r"
,
"
\\
t"
,
"
\\
f"
,
"
\\
b"
);
$unescaped
=
array
(
'\\'
,
'/'
,
'"'
,
"
\n
"
,
"
\r
"
,
"
\t
"
,
"
\x08
"
,
"
\x0c
"
);
$result
=
str_replace
(
$escaped
,
$unescaped
,
$string
);
return
$result
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment