forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita18328b
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 parentd43a97e commita18328b
File tree
5 files changed
+90
-18
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
5 files changed
+90
-18
lines changedLines changed: 3 additions & 2 deletions
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 |
| |
|
Lines changed: 6 additions & 4 deletions
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 |
| |
|
Lines changed: 29 additions & 12 deletions
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 |
| |
| |||
4461 | 4469 |
| |
4462 | 4470 |
| |
4463 | 4471 |
| |
| 4472 | + | |
4464 | 4473 |
| |
4465 | 4474 |
| |
4466 | 4475 |
| |
| |||
4985 | 4994 |
| |
4986 | 4995 |
| |
4987 | 4996 |
| |
| 4997 | + | |
4988 | 4998 |
| |
4989 | 4999 |
| |
4990 | 5000 |
| |
4991 | 5001 |
| |
4992 | 5002 |
| |
4993 | 5003 |
| |
4994 | 5004 |
| |
| 5005 | + | |
| 5006 | + | |
| 5007 | + | |
| 5008 | + | |
| 5009 | + | |
4995 | 5010 |
| |
4996 | 5011 |
| |
4997 | 5012 |
| |
| |||
5000 | 5015 |
| |
5001 | 5016 |
| |
5002 | 5017 |
| |
5003 |
| - | |
5004 |
| - | |
| 5018 | + | |
| 5019 | + | |
5005 | 5020 |
| |
5006 | 5021 |
| |
5007 | 5022 |
| |
| |||
5014 | 5029 |
| |
5015 | 5030 |
| |
5016 | 5031 |
| |
5017 |
| - | |
5018 |
| - | |
| 5032 | + | |
| 5033 | + | |
5019 | 5034 |
| |
5020 | 5035 |
| |
5021 | 5036 |
| |
| |||
5055 | 5070 |
| |
5056 | 5071 |
| |
5057 | 5072 |
| |
5058 |
| - | |
5059 |
| - | |
| 5073 | + | |
| 5074 | + | |
5060 | 5075 |
| |
5061 | 5076 |
| |
5062 | 5077 |
| |
| |||
5099 | 5114 |
| |
5100 | 5115 |
| |
5101 | 5116 |
| |
5102 |
| - | |
5103 |
| - | |
| 5117 | + | |
| 5118 | + | |
5104 | 5119 |
| |
5105 | 5120 |
| |
5106 | 5121 |
| |
| |||
5509 | 5524 |
| |
5510 | 5525 |
| |
5511 | 5526 |
| |
| 5527 | + | |
| 5528 | + | |
5512 | 5529 |
| |
5513 | 5530 |
| |
5514 | 5531 |
| |
|
Lines changed: 34 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
5192 | 5192 |
| |
5193 | 5193 |
| |
5194 | 5194 |
| |
| 5195 | + | |
| 5196 | + | |
| 5197 | + | |
| 5198 | + | |
| 5199 | + | |
| 5200 | + | |
| 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 | + | |
5195 | 5229 |
| |
5196 | 5230 |
| |
5197 | 5231 |
| |
|
Lines changed: 18 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1405 | 1405 |
| |
1406 | 1406 |
| |
1407 | 1407 |
| |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
1408 | 1426 |
| |
1409 | 1427 |
| |
1410 | 1428 |
| |
|
0 commit comments
Comments
(0)