forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitd79b76b
committed
Fix jsonb subscripting to cope with toasted subscript values.
jsonb_get_element() was incautious enough to use VARDATA() andVARSIZE() directly on an arbitrary text Datum. That of coursefails if the Datum is short-header, compressed, or out-of-line.The typical result would be failing to match any element of ajsonb object, though matching the wrong one seems possible as well.setPathObject() was slightly brighter, in that it used VARDATA_ANYand VARSIZE_ANY_EXHDR, but that only kept it out of trouble forshort-header Datums. push_path() had the same issue. This couldresult in faulty subscripted insertions, though keys long enough tocause a problem are likely rare in the wild.Having seen these, I looked around for unsafe usages in the restof the adt/json* files. There are a couple of places where it's notimmediately 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, removesome other usages of VARDATA/VARSIZE on Datums we just extracted froma text array. Those aren't actively broken, but they will become soif we ever start allowing short-header array elements, which does notseem like a terribly unreasonable thing to do. In any case they arenot great coding examples, and they could also do with commentspointing 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 toDavid Johnston for initial investigation. Back-patch to v14 wherejsonb subscripting was introduced.Discussion:https://postgr.es/m/205321670615953@mail.yandex.ru1 parent8b5ba2f commitd79b76b
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 | |
|---|---|---|---|
| |||
896 | 896 | | |
897 | 897 | | |
898 | 898 | | |
| 899 | + | |
899 | 900 | | |
900 | | - | |
901 | | - | |
| 901 | + | |
| 902 | + | |
902 | 903 | | |
903 | 904 | | |
904 | 905 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
68 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| |||
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
100 | | - | |
101 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
102 | 104 | | |
103 | 105 | | |
104 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
516 | 516 | | |
517 | 517 | | |
518 | 518 | | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
519 | 525 | | |
520 | 526 | | |
521 | 527 | | |
| |||
1518 | 1524 | | |
1519 | 1525 | | |
1520 | 1526 | | |
| 1527 | + | |
| 1528 | + | |
1521 | 1529 | | |
1522 | | - | |
1523 | | - | |
| 1530 | + | |
| 1531 | + | |
1524 | 1532 | | |
1525 | 1533 | | |
1526 | 1534 | | |
| |||
1693 | 1701 | | |
1694 | 1702 | | |
1695 | 1703 | | |
1696 | | - | |
1697 | | - | |
| 1704 | + | |
| 1705 | + | |
1698 | 1706 | | |
1699 | 1707 | | |
1700 | 1708 | | |
| |||
4349 | 4357 | | |
4350 | 4358 | | |
4351 | 4359 | | |
| 4360 | + | |
4352 | 4361 | | |
4353 | 4362 | | |
4354 | 4363 | | |
| |||
4873 | 4882 | | |
4874 | 4883 | | |
4875 | 4884 | | |
| 4885 | + | |
4876 | 4886 | | |
4877 | 4887 | | |
4878 | 4888 | | |
4879 | 4889 | | |
4880 | 4890 | | |
4881 | 4891 | | |
4882 | 4892 | | |
| 4893 | + | |
| 4894 | + | |
| 4895 | + | |
| 4896 | + | |
| 4897 | + | |
4883 | 4898 | | |
4884 | 4899 | | |
4885 | 4900 | | |
| |||
4888 | 4903 | | |
4889 | 4904 | | |
4890 | 4905 | | |
4891 | | - | |
4892 | | - | |
| 4906 | + | |
| 4907 | + | |
4893 | 4908 | | |
4894 | 4909 | | |
4895 | 4910 | | |
| |||
4902 | 4917 | | |
4903 | 4918 | | |
4904 | 4919 | | |
4905 | | - | |
4906 | | - | |
| 4920 | + | |
| 4921 | + | |
4907 | 4922 | | |
4908 | 4923 | | |
4909 | 4924 | | |
| |||
4943 | 4958 | | |
4944 | 4959 | | |
4945 | 4960 | | |
4946 | | - | |
4947 | | - | |
| 4961 | + | |
| 4962 | + | |
4948 | 4963 | | |
4949 | 4964 | | |
4950 | 4965 | | |
| |||
4987 | 5002 | | |
4988 | 5003 | | |
4989 | 5004 | | |
4990 | | - | |
4991 | | - | |
| 5005 | + | |
| 5006 | + | |
4992 | 5007 | | |
4993 | 5008 | | |
4994 | 5009 | | |
| |||
5397 | 5412 | | |
5398 | 5413 | | |
5399 | 5414 | | |
| 5415 | + | |
| 5416 | + | |
5400 | 5417 | | |
5401 | 5418 | | |
5402 | 5419 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5199 | 5199 | | |
5200 | 5200 | | |
5201 | 5201 | | |
| 5202 | + | |
| 5203 | + | |
| 5204 | + | |
| 5205 | + | |
| 5206 | + | |
| 5207 | + | |
| 5208 | + | |
| 5209 | + | |
| 5210 | + | |
| 5211 | + | |
| 5212 | + | |
| 5213 | + | |
| 5214 | + | |
| 5215 | + | |
| 5216 | + | |
| 5217 | + | |
| 5218 | + | |
| 5219 | + | |
| 5220 | + | |
| 5221 | + | |
| 5222 | + | |
| 5223 | + | |
| 5224 | + | |
| 5225 | + | |
| 5226 | + | |
| 5227 | + | |
| 5228 | + | |
| 5229 | + | |
| 5230 | + | |
| 5231 | + | |
| 5232 | + | |
| 5233 | + | |
| 5234 | + | |
| 5235 | + | |
5202 | 5236 | | |
5203 | 5237 | | |
5204 | 5238 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1415 | 1415 | | |
1416 | 1416 | | |
1417 | 1417 | | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
1418 | 1436 | | |
1419 | 1437 | | |
1420 | 1438 | | |
| |||
0 commit comments
Comments
(0)