control character check in JSON type seems broken

Поиск
Список
Период
Сортировка
От Shigeru Hanada
Тема control character check in JSON type seems broken
Дата
Msg-id CAEZqfEdbRO8MhH83Fma9uSQhCfWmHpgcbm9Lwucq2HSwCHhbdQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: control character check in JSON type seems broken  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
Hi,

A Japanese user found strange behavior in JSON type, so I'd like to
share the issue here.  He simply tested casting a string literal to json
type, and got an unexpected error when he used a Japanese word as name
and/or value of JSON object.

In the example below, "キー" is a Japanese word which means "key", and
its first letter has byte sequence "0xe3 0x82 0xad" in UTF-8.

postgres=# select '{"キー":"value"}'::json;
ERROR:  invalid input syntax for type json
LINE 1: select '{"キー":"value"}'::json;
                ^
DETAIL:  line 1: Character "  ・ must be escaped.

With some debugging, I found that the problem is in json_lex_string().

json_lex_string() misjudges that the token "キー" contains naked
(not-escaped) control character, because its first byte is 0xe3 and it's
-29 for signed char interpreting, and it's less than 32.  We need to
cast to unsigned char (or use unsigned variable) here.

In addition, error message above seems corrupted in my environment.
Here we check not-escaped control character, so printing it with %c
formatting might break log files.  How about using decimal or hex dump
in such cases?

Please see attached patch which contains workaround for this issue.

Regards,
--
Shigeru HANADA

Вложения

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: BUG #6672: Memory leaks in dumputils.c
Следующее
От: jo
Дата:
Сообщение: Re: BUG #6669: unique index w/ multiple columns and NULLs