| From: | Ishjaap Singh <ishjaap(dot)singh07(at)gmail(dot)com> |
|---|---|
| To: | Andrey Rachitskiy <pl0h0yp1(at)gmail(dot)com> |
| Cc: | e1638616(at)u(dot)nus(dot)edu, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19956: json #>, #>> and json_extract_path resolve a negative array index against an earlier sibling array |
| Date: | 2026-12-03 17:21:12 |
| Message-ID: | CA+Y2BmeNSWTmCm2Q1L9SQ9YyzP-5y4tiaeAEZ3_fTzWqvpHnrA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi Andrey,
I reviewed the patch on master (d637007e62a). It applies, builds
without warnings and passes make check. Five of the seven new tests
fail without the fix.
I compared json #> and #>> with jsonb on 30 paths: sibling arrays
before and after the target, nested negative indexes, empty arrays and
out-of-range indexes. Without the patch 15 differ from jsonb, with it
4 do, all with duplicate keys. REL_14_STABLE has the same bug, but the
patch doesn't apply to 18 and older (the palloc_array() hunk in
get_worker()).
One problem with duplicate keys:
SELECT '{"x":[0,0,0,0,0,0,0],"a":[1,2,3],"a":[7,8]}'::json
#> '{a,-3}';
Master gives NULL, like jsonb and the chained -> form. The patch gives
1, from the first "a" (#>> too). The first "a" now matches, and the
second one doesn't clear that result. That's BUG #19970 [1]:
get_object_field_start() only clears the result when the key is the
last path element. So I think #19970 should be fixed together with
this. Would you like to include it in your patch, or should I send a
separate fix for it?
Minor: is the (size_t) -idx <= input_length check needed? A negative
index that is too large already gives NULL on master, for example
'[1,2,3]'::json #> '{-1000}', so it seems to only skip the counting.
Otherwise the patch looks right to me.
[1] https://www.postgresql.org/message-id/19970-ce2ab938d31adac4%40postgresql.org
Regards,
Ishjaap Singh
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nathan Bossart | 2026-12-03 17:32:45 | Re: JSON_SERIALIZE for JSONB returns parts of the internal JSONB representation |
| Previous Message | Fujii Masao | 2026-12-03 16:06:39 | Re: BUG #19952: psql \d+ omits nondefault replica identity for partitioned tables |