Commit b0feda7
committed
Fix jsonb subscripting to cope with toasted subscript values.
jsonb_get_element() was incautious enough to use VARDATA() and
VARSIZE() directly on an arbitrary text Datum. That of course
fails if the Datum is short-header, compressed, or out-of-line.
The typical result would be failing to match any element of a
jsonb object, though matching the wrong one seems possible as well.
setPathObject() was slightly brighter, in that it used VARDATA_ANY
and VARSIZE_ANY_EXHDR, but that only kept it out of trouble for
short-header Datums. push_path() had the same issue. This could
result in faulty subscripted insertions, though keys long enough to
cause a problem are likely rare in the wild.
Having seen these, I looked around for unsafe usages in the rest
of the adt/json* files. There are a couple of places where it's not
immediately obvious that the Datum can't be compressed or out-of-line,
so I added pg_detoast_datum_packed() to cope if it is. Also, remove
some other usages of VARDATA/VARSIZE on Datums we just extracted from
a text array. Those aren't actively broken, but they will become so
if we ever start allowing short-header array elements, which does not
seem like a terribly unreasonable thing to do. In any case they are
not great coding examples, and they could also do with comments
pointing out that we're assuming we don't need pg_detoast_datum_packed.
Per report from exe-dealer@yandex.ru. Patch by me, but thanks to
David Johnston for initial investigation. Back-patch to v14 where
jsonb subscripting was introduced.
Discussion: https://postgr.es/m/205321670615953@mail.yandex.ru1 parent 101c37c commit b0feda7
File tree
5 files changed
+90
-18
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
5 files changed
+90
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
894 | 894 | | |
895 | 895 | | |
896 | 896 | | |
| 897 | + | |
897 | 898 | | |
898 | | - | |
899 | | - | |
| 899 | + | |
| 900 | + | |
900 | 901 | | |
901 | 902 | | |
902 | 903 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
68 | 69 | | |
69 | 70 | | |
70 | 71 | | |
| |||
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | | - | |
99 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
100 | 102 | | |
101 | 103 | | |
102 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
527 | 527 | | |
528 | 528 | | |
529 | 529 | | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
530 | 536 | | |
531 | 537 | | |
532 | 538 | | |
| |||
1559 | 1565 | | |
1560 | 1566 | | |
1561 | 1567 | | |
| 1568 | + | |
| 1569 | + | |
1562 | 1570 | | |
1563 | | - | |
1564 | | - | |
| 1571 | + | |
| 1572 | + | |
1565 | 1573 | | |
1566 | 1574 | | |
1567 | 1575 | | |
| |||
1734 | 1742 | | |
1735 | 1743 | | |
1736 | 1744 | | |
1737 | | - | |
1738 | | - | |
| 1745 | + | |
| 1746 | + | |
1739 | 1747 | | |
1740 | 1748 | | |
1741 | 1749 | | |
| |||
4456 | 4464 | | |
4457 | 4465 | | |
4458 | 4466 | | |
| 4467 | + | |
4459 | 4468 | | |
4460 | 4469 | | |
4461 | 4470 | | |
| |||
4977 | 4986 | | |
4978 | 4987 | | |
4979 | 4988 | | |
| 4989 | + | |
4980 | 4990 | | |
4981 | 4991 | | |
4982 | 4992 | | |
4983 | 4993 | | |
4984 | 4994 | | |
4985 | 4995 | | |
4986 | 4996 | | |
| 4997 | + | |
| 4998 | + | |
| 4999 | + | |
| 5000 | + | |
| 5001 | + | |
4987 | 5002 | | |
4988 | 5003 | | |
4989 | 5004 | | |
| |||
4992 | 5007 | | |
4993 | 5008 | | |
4994 | 5009 | | |
4995 | | - | |
4996 | | - | |
| 5010 | + | |
| 5011 | + | |
4997 | 5012 | | |
4998 | 5013 | | |
4999 | 5014 | | |
| |||
5006 | 5021 | | |
5007 | 5022 | | |
5008 | 5023 | | |
5009 | | - | |
5010 | | - | |
| 5024 | + | |
| 5025 | + | |
5011 | 5026 | | |
5012 | 5027 | | |
5013 | 5028 | | |
| |||
5047 | 5062 | | |
5048 | 5063 | | |
5049 | 5064 | | |
5050 | | - | |
5051 | | - | |
| 5065 | + | |
| 5066 | + | |
5052 | 5067 | | |
5053 | 5068 | | |
5054 | 5069 | | |
| |||
5091 | 5106 | | |
5092 | 5107 | | |
5093 | 5108 | | |
5094 | | - | |
5095 | | - | |
| 5109 | + | |
| 5110 | + | |
5096 | 5111 | | |
5097 | 5112 | | |
5098 | 5113 | | |
| |||
5505 | 5520 | | |
5506 | 5521 | | |
5507 | 5522 | | |
| 5523 | + | |
| 5524 | + | |
5508 | 5525 | | |
5509 | 5526 | | |
5510 | 5527 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5224 | 5224 | | |
5225 | 5225 | | |
5226 | 5226 | | |
| 5227 | + | |
| 5228 | + | |
| 5229 | + | |
| 5230 | + | |
| 5231 | + | |
| 5232 | + | |
| 5233 | + | |
| 5234 | + | |
| 5235 | + | |
| 5236 | + | |
| 5237 | + | |
| 5238 | + | |
| 5239 | + | |
| 5240 | + | |
| 5241 | + | |
| 5242 | + | |
| 5243 | + | |
| 5244 | + | |
| 5245 | + | |
| 5246 | + | |
| 5247 | + | |
| 5248 | + | |
| 5249 | + | |
| 5250 | + | |
| 5251 | + | |
| 5252 | + | |
| 5253 | + | |
| 5254 | + | |
| 5255 | + | |
| 5256 | + | |
| 5257 | + | |
| 5258 | + | |
| 5259 | + | |
| 5260 | + | |
5227 | 5261 | | |
5228 | 5262 | | |
5229 | 5263 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1421 | 1421 | | |
1422 | 1422 | | |
1423 | 1423 | | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
1424 | 1442 | | |
1425 | 1443 | | |
1426 | 1444 | | |
| |||
0 commit comments