- Notifications
You must be signed in to change notification settings - Fork5
Commite80c85e
committed
Add defenses against putting expanded objects into Const nodes.
Putting a reference to an expanded-format value into a Const node would bea bad idea for a couple of reasons. It'd be possible for the supposedlyimmutable Const to change value, if something modified the referencedvariable ... in fact, if the Const's reference were R/W, any function thathas the Const as argument might itself change it at runtime. Also, becausedatumIsEqual() is pretty simplistic, the Const might fail to compare equalto other Consts that it should compare equal to, notably including copiesof itself. This could lead to unexpected planner behavior, such as "couldnot find pathkey item to sort" errors or inferior plans.I have not been able to find any way to get an expanded value into a Constwithin the existing core code; but Paul Ramsey was able to trigger theproblem by writing a datatype input function that returns an expandedvalue.The best fix seems to be to establish a rule that varlena values beingplaced into Const nodes should be passed through pg_detoast_datum().That will do nothing (and cost little) in normal cases, but it will flattenexpanded values and thereby avoid the above problems. Also, it willconvert short-header or compressed values into canonical format, which willavoid possible unexpected lack-of-equality issues for those cases too.And it provides a last-ditch defense against putting a toasted value intoa Const, which we already knew was dangerous, cf commit2b0c86b.(In the light of this discussion, I'm no longer sure that that commitprovided 100% protection against such cases, but this fix should do it.)The test added in commit65c3d05 to catch datatype input functionswith unstable results would fail for functions that returned expandedvalues; but it seems a bit uncharitable to deem a result unstable justbecause it's expressed in expanded form, so revise the coding so that wecheck for bitwise equality only after applying pg_detoast_datum(). That'sa sufficient condition anyway given the new rule about detoasting whenforming a Const.Back-patch to 9.5 where the expanded-object facility was added. It'spossible that this should go back further; but in the absence of clearevidence that there's any live bug in older branches, I'll refrain for now.1 parent34bda20 commite80c85e
File tree
5 files changed
+55
-31
lines changed- src
- backend
- nodes
- optimizer/util
- parser
- include/nodes
5 files changed
+55
-31
lines changedLines changed: 9 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
17 | 17 |
| |
18 | 18 |
| |
19 | 19 |
| |
| 20 | + | |
20 | 21 |
| |
21 | 22 |
| |
22 | 23 |
| |
| |||
302 | 303 |
| |
303 | 304 |
| |
304 | 305 |
| |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
305 | 314 |
| |
306 | 315 |
| |
307 | 316 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
4655 | 4655 |
| |
4656 | 4656 |
| |
4657 | 4657 |
| |
4658 |
| - | |
| 4658 | + | |
| 4659 | + | |
4659 | 4660 |
| |
4660 | 4661 |
| |
4661 | 4662 |
| |
|
Lines changed: 38 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
26 | 26 |
| |
27 | 27 |
| |
28 | 28 |
| |
| 29 | + | |
29 | 30 |
| |
30 | 31 |
| |
31 | 32 |
| |
| |||
308 | 309 |
| |
309 | 310 |
| |
310 | 311 |
| |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
311 | 349 |
| |
312 | 350 |
| |
313 | 351 |
| |
|
Lines changed: 1 addition & 30 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
23 | 23 |
| |
24 | 24 |
| |
25 | 25 |
| |
26 |
| - | |
27 | 26 |
| |
28 | 27 |
| |
29 | 28 |
| |
| |||
639 | 638 |
| |
640 | 639 |
| |
641 | 640 |
| |
642 |
| - | |
643 | 641 |
| |
644 |
| - | |
645 |
| - | |
646 |
| - | |
647 |
| - | |
648 |
| - | |
649 |
| - | |
650 |
| - | |
651 |
| - | |
652 |
| - | |
653 |
| - | |
654 |
| - | |
655 |
| - | |
656 |
| - | |
657 |
| - | |
658 |
| - | |
659 |
| - | |
660 |
| - | |
661 |
| - | |
662 |
| - | |
663 |
| - | |
664 |
| - | |
665 |
| - | |
666 |
| - | |
667 |
| - | |
668 |
| - | |
669 |
| - | |
670 |
| - | |
671 |
| - | |
| 642 | + | |
672 | 643 |
| |
673 | 644 |
| |
674 | 645 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
165 | 165 |
| |
166 | 166 |
| |
167 | 167 |
| |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
168 | 173 |
| |
169 | 174 |
| |
170 | 175 |
| |
|
0 commit comments
Comments
(0)