forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit5548416
committed
Fix oversights in array manipulation.
The nested-arrays code path in ExecEvalArrayExpr() used palloc toallocate the result array, whereas every other array-creating functionhas used palloc0 since18c0b4e. This mostly works, but unused bitspast the end of the nulls bitmap may end up undefined. That causesvalgrind complaints with -DWRITE_READ_PARSE_PLAN_TREES, and couldcause planner misbehavior as cited in18c0b4e. There seems no verygood reason why we should strive to avoid palloc0 in just this one case,so fix it the easy way with s/palloc/palloc0/.While looking at that I noted that we also failed to check for overflowof "nbytes" and "nitems" while summing the sizes of the sub-arrays,potentially allowing a crash due to undersized output allocation.For "nbytes", follow the policy used by other array-munging code ofchecking for overflow after each addition. (As elsewhere, the lastaddition of the array's overhead space doesn't need an extra check,since palloc itself will catch a value between 1Gb and 2Gb.)For "nitems", there's no very good reason to sum the inputs at all,since we can perfectly well use ArrayGetNItems' result instead ofignoring it.Per discussion of this bug, also remove redundant zeroing of thenulls bitmap in array_set_element and array_set_slice.Patch by Alexander Lakhin and myself, per bug #17858 from AlexanderLakhin; thanks also to Richard Guo. These bugs are a dozen years old,so back-patch to all supported branches.Discussion:https://postgr.es/m/17858-8fd287fd3663d051@postgresql.org1 parentd435f15 commit5548416
2 files changed
+11
-8
lines changedLines changed: 9 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2659 | 2659 |
| |
2660 | 2660 |
| |
2661 | 2661 |
| |
2662 |
| - | |
| 2662 | + | |
2663 | 2663 |
| |
2664 | 2664 |
| |
2665 | 2665 |
| |
| |||
2754 | 2754 |
| |
2755 | 2755 |
| |
2756 | 2756 |
| |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
2757 | 2763 |
| |
2758 | 2764 |
| |
2759 |
| - | |
2760 | 2765 |
| |
2761 | 2766 |
| |
2762 | 2767 |
| |
| |||
2790 | 2795 |
| |
2791 | 2796 |
| |
2792 | 2797 |
| |
2793 |
| - | |
| 2798 | + | |
2794 | 2799 |
| |
2795 | 2800 |
| |
2796 | 2801 |
| |
| |||
2804 | 2809 |
| |
2805 | 2810 |
| |
2806 | 2811 |
| |
2807 |
| - | |
| 2812 | + | |
2808 | 2813 |
| |
2809 | 2814 |
| |
2810 | 2815 |
| |
|
Lines changed: 2 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2483 | 2483 |
| |
2484 | 2484 |
| |
2485 | 2485 |
| |
2486 |
| - | |
2487 |
| - | |
| 2486 | + | |
2488 | 2487 |
| |
2489 | 2488 |
| |
2490 | 2489 |
| |
| |||
3100 | 3099 |
| |
3101 | 3100 |
| |
3102 | 3101 |
| |
3103 |
| - | |
3104 |
| - | |
| 3102 | + | |
3105 | 3103 |
| |
3106 | 3104 |
| |
3107 | 3105 |
| |
|
0 commit comments
Comments
(0)