aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/jsonapi.c4
-rw-r--r--src/test/modules/test_json_parser/t/002_inline.pl8
2 files changed, 10 insertions, 2 deletions
diff --git a/src/common/jsonapi.c b/src/common/jsonapi.c
index fc0cb369749..26e1f43ed38 100644
--- a/src/common/jsonapi.c
+++ b/src/common/jsonapi.c
@@ -1689,8 +1689,8 @@ json_lex_string(JsonLexContext *lex)
} while (0)
#define FAIL_AT_CHAR_END(code) \
do { \
- lex->token_terminator = \
- s + pg_encoding_mblen_bounded(lex->input_encoding, s); \
+ char *term = s + pg_encoding_mblen(lex->input_encoding, s); \
+ lex->token_terminator = (term <= end) ? term : end; \
return code; \
} while (0)
diff --git a/src/test/modules/test_json_parser/t/002_inline.pl b/src/test/modules/test_json_parser/t/002_inline.pl
index b95cb6b16a9..7c4134b3a6a 100644
--- a/src/test/modules/test_json_parser/t/002_inline.pl
+++ b/src/test/modules/test_json_parser/t/002_inline.pl
@@ -127,4 +127,12 @@ test(
'"\\\\\\\\\\\\\\"',
error => qr/Token ""\\\\\\\\\\\\\\"" is invalid/);
+# Case with three bytes: double-quote, backslash and <f5>.
+# Both invalid-token and invalid-escape are possible errors, because for
+# smaller chunk sizes the incremental parser skips the string parsing when
+# it cannot find an ending quote.
+test("incomplete UTF-8 sequence",
+ "\"\\\x{F5}",
+ error => qr/(Token|Escape sequence) ""?\\\x{F5}" is invalid/);
+
done_testing();