2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

In JSONParser::getToken reject illegal control characters

This commit is contained in:
m-holger 2023-01-29 11:39:15 +00:00
parent 1b89e7684e
commit 5ac6a12e0a
11 changed files with 30 additions and 5 deletions

View File

@ -780,10 +780,22 @@ JSONParser::getToken()
}
}
if (*p == 0) {
QTC::TC("libtests", "JSON parse null character");
throw std::runtime_error(
"JSON: null character at offset " + std::to_string(offset));
if ((*p < 32 && *p >= 0)) {
if (*p == '\t' || *p == '\n' || *p == '\r') {
// Legal white space not permitted in strings. This will always
// end the current token (unless we are still before the start
// of the token).
if (lex_state == ls_top) {
// Continue with token
} else {
// done
}
} else {
QTC::TC("libtests", "JSON parse null character");
throw std::runtime_error(
"JSON: control or null character at offset " +
std::to_string(offset));
}
}
action = append;
switch (lex_state) {

View File

@ -125,6 +125,10 @@ my @bad = (
"e after minus", # 42
"missing digit after e", # 43
"missing digit after e+/-", # 44
# "tab char in string", # 45
# "cr char in string", # 46
# "lf char in string", # 47
# "bs char in string", # 48
);
my $i = 0;

View File

@ -1 +1 @@
exception: bad-18.json: JSON: null character at offset 5
exception: bad-18.json: JSON: control or null character at offset 5

View File

@ -0,0 +1 @@
"Tab in str ing"

View File

@ -0,0 +1 @@
"Tab in str\ting"

View File

@ -0,0 +1 @@
"cr in str ing"

View File

@ -0,0 +1 @@
"cr in str\ring"

View File

@ -0,0 +1,2 @@
"lf in str
ing"

View File

@ -0,0 +1 @@
"lf in str\ning"

View File

@ -0,0 +1 @@
"bs in string"

View File

@ -0,0 +1 @@
exception: bad-48.json: JSON: control or null character at offset 10