Re: Bug in searching path in jsonb_set when walking through JSONB array

Поиск
Список
Период
Сортировка
От Vitaly Burovoy
Тема Re: Bug in searching path in jsonb_set when walking through JSONB array
Дата
Msg-id CAKOSWNnwXpizn4BTjrhasjzVckA80EQMotaemMVt9xQnjq5Dtg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Bug in searching path in jsonb_set when walking through JSONB array  (Oleg Bartunov <obartunov@gmail.com>)
Ответы Re: Bug in searching path in jsonb_set when walking through JSONB array  (Michael Paquier <michael.paquier@gmail.com>)
Список pgsql-hackers
On 2016-03-23, Oleg Bartunov <obartunov@gmail.com> wrote:
> On Wed, Mar 23, 2016 at 6:37 AM, Vitaly Burovoy <vitaly.burovoy@gmail.com>
> wrote:
>
>> Hello, Hackers!
>>
>> While I was reviewed a patch with "json_insert" function I found a bug
>> which wasn't connected with the patch and reproduced at master.
>>
>> It claims about non-integer whereas input values are obvious integers
>> and in an allowed range.
>> More testing lead to understanding it appears when numbers length are
>> multiplier of 4:
>>
>> postgres=# select jsonb_set('{"a":[[],1,2,3],"b":[]}', '{"a", 9999}',
>> '"4"');
>> ERROR:  path element at the position 2 is not an integer
>>
>
> Hmm, I see in master
>
> select version();
>                                                      version
> -----------------------------------------------------------------------------------------------------------------
>  PostgreSQL 9.6devel on x86_64-apple-darwin15.4.0, compiled by Apple LLVM
> version 7.3.0 (clang-703.0.29), 64-bit
> (1 row)
>
> select jsonb_set('{"a":[[],1,2,3],"b":[]}', '{"a", 9999}', '"4"');
>              jsonb_set
> ------------------------------------
>  {"a": [[], 1, 2, 3, "4"], "b": []}
> (1 row)

Yes, I can't reproduce it with "CFLAGS=-O2", but it is still
reproduced with "CFLAGS='-O0 -g3'".

postgres=# select version();                                                version
----------------------------------------------------------------------------------------------------------PostgreSQL
9.6develon x86_64-pc-linux-gnu, compiled by gcc (Gentoo
 
4.8.4 p1.4, pie-0.6.1) 4.8.4, 64-bit
(1 row)

postgres=# select jsonb_set('{"a":[[],1,2,3],"b":[]}', '{"a", 9999}', '"4"');
ERROR:  path element at the position 2 is not an integer


It depends on memory after the string. In debug mode it always (most
of the time?) has a garbage (in my case the char '~' following by
'\x7f' multiple times) there.

I think it is just a question of complexity of reproducing in release,
not a question whether there is a bug or not.

All the other occurrences of strtol in the file have
TextDatumGetCString before, except the occurrence in the setPathArray
function. It seems its type is TEXT (which is not null-terminated),
not cstring.

-- 
Best regards,
Vitaly Burovoy



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

Предыдущее
От: Pavan Deolasee
Дата:
Сообщение: Re: pg_xlogdump fails to handle WAL file with multi-page XLP_FIRST_IS_CONTRECORD data
Следующее
От: Yury Zhuravlev
Дата:
Сообщение: Re: NOT EXIST for PREPARE