forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit4bd3fad
committed
Fix integer-overflow corner cases in substring() functions.
If the substring start index and length overflow when added together,substring() misbehaved, either throwing a bogus "negative substringlength" error on a case that should succeed, or failing to complain thata negative length is negative (and instead returning the whole string,in most cases). Unsurprisingly, the text, bytea, and bit variants ofthe function all had this issue. Rearrange the logic to ensure thatnegative lengths are always rejected, and add an overflow check tohandle the other case.Also install similar guards into detoast_attr_slice() (neeheap_tuple_untoast_attr_slice()), since it's far from clear thatno other code paths leading to that function could pass it valuesthat would overflow.Patch by myself and Pavel Stehule, per bug #16804 from Rafi Shamim.Back-patch to v11. While these bugs are old, the common/int.hinfrastructure for overflow-detecting arithmetic didn't exist beforecommit4d6ad31, and it doesn't seem like these misbehaviors are badenough to justify developing a standalone fix for the older branches.Discussion:https://postgr.es/m/16804-f4eeeb6c11ba71d4@postgresql.org1 parent87c23d3 commit4bd3fad
File tree
7 files changed
+195
-63
lines changed- src
- backend
- access/common
- utils/adt
- test/regress
- expected
- sql
7 files changed
+195
-63
lines changedLines changed: 26 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
17 | 17 |
| |
18 | 18 |
| |
19 | 19 |
| |
| 20 | + | |
20 | 21 |
| |
21 | 22 |
| |
22 | 23 |
| |
| |||
196 | 197 |
| |
197 | 198 |
| |
198 | 199 |
| |
199 |
| - | |
| 200 | + | |
| 201 | + | |
200 | 202 |
| |
201 | 203 |
| |
202 | 204 |
| |
| |||
206 | 208 |
| |
207 | 209 |
| |
208 | 210 |
| |
| 211 | + | |
209 | 212 |
| |
210 | 213 |
| |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
211 | 226 |
| |
212 | 227 |
| |
213 | 228 |
| |
| |||
223 | 238 |
| |
224 | 239 |
| |
225 | 240 |
| |
226 |
| - | |
| 241 | + | |
227 | 242 |
| |
228 | 243 |
| |
229 | 244 |
| |
230 | 245 |
| |
231 | 246 |
| |
232 | 247 |
| |
233 | 248 |
| |
234 |
| - | |
| 249 | + | |
235 | 250 |
| |
236 | 251 |
| |
237 | 252 |
| |
| |||
270 | 285 |
| |
271 | 286 |
| |
272 | 287 |
| |
273 |
| - | |
274 |
| - | |
| 288 | + | |
| 289 | + | |
275 | 290 |
| |
276 | 291 |
| |
277 | 292 |
| |
| |||
297 | 312 |
| |
298 | 313 |
| |
299 | 314 |
| |
300 |
| - | |
301 |
| - | |
| 315 | + | |
302 | 316 |
| |
303 | 317 |
| |
304 | 318 |
| |
| |||
410 | 424 |
| |
411 | 425 |
| |
412 | 426 |
| |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
413 | 432 |
| |
414 | 433 |
| |
415 | 434 |
| |
|
Lines changed: 16 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1059 | 1059 |
| |
1060 | 1060 |
| |
1061 | 1061 |
| |
1062 |
| - | |
| 1062 | + | |
1063 | 1063 |
| |
1064 | 1064 |
| |
1065 | 1065 |
| |
| |||
1072 | 1072 |
| |
1073 | 1073 |
| |
1074 | 1074 |
| |
1075 |
| - | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
1076 | 1084 |
| |
1077 |
| - | |
1078 |
| - | |
1079 | 1085 |
| |
1080 |
| - | |
1081 |
| - | |
| 1086 | + | |
| 1087 | + | |
1082 | 1088 |
| |
1083 |
| - | |
1084 |
| - | |
1085 |
| - | |
1086 |
| - | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
1087 | 1093 |
| |
1088 | 1094 |
| |
1089 | 1095 |
| |
|
Lines changed: 64 additions & 46 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
868 | 868 |
| |
869 | 869 |
| |
870 | 870 |
| |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
871 | 878 |
| |
872 | 879 |
| |
873 | 880 |
| |
874 | 881 |
| |
875 |
| - | |
876 |
| - | |
877 | 882 |
| |
878 | 883 |
| |
879 | 884 |
| |
880 |
| - | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
881 | 894 |
| |
882 |
| - | |
883 |
| - | |
884 |
| - | |
885 | 895 |
| |
886 |
| - | |
887 |
| - | |
| 896 | + | |
| 897 | + | |
888 | 898 |
| |
889 |
| - | |
890 |
| - | |
891 |
| - | |
892 |
| - | |
893 |
| - | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
894 | 903 |
| |
895 | 904 |
| |
896 | 905 |
| |
| |||
904 | 913 |
| |
905 | 914 |
| |
906 | 915 |
| |
907 |
| - | |
908 |
| - | |
| 916 | + | |
| 917 | + | |
909 | 918 |
| |
910 | 919 |
| |
911 | 920 |
| |
| |||
926 | 935 |
| |
927 | 936 |
| |
928 | 937 |
| |
929 |
| - | |
930 |
| - | |
931 |
| - | |
932 |
| - | |
933 |
| - | |
934 |
| - | |
935 | 938 |
| |
936 | 939 |
| |
937 | 940 |
| |
| |||
942 | 945 |
| |
943 | 946 |
| |
944 | 947 |
| |
945 |
| - | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
946 | 957 |
| |
947 |
| - | |
948 |
| - | |
949 | 958 |
| |
950 |
| - | |
951 |
| - | |
| 959 | + | |
| 960 | + | |
952 | 961 |
| |
953 |
| - | |
954 |
| - | |
955 |
| - | |
956 |
| - | |
957 |
| - | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
958 | 966 |
| |
959 | 967 |
| |
960 | 968 |
| |
| |||
972 | 980 |
| |
973 | 981 |
| |
974 | 982 |
| |
| 983 | + | |
975 | 984 |
| |
976 |
| - | |
| 985 | + | |
| 986 | + | |
977 | 987 |
| |
978 | 988 |
| |
979 | 989 |
| |
| |||
3309 | 3319 |
| |
3310 | 3320 |
| |
3311 | 3321 |
| |
3312 |
| - | |
3313 |
| - | |
| 3322 | + | |
| 3323 | + | |
| 3324 | + | |
3314 | 3325 |
| |
| 3326 | + | |
| 3327 | + | |
| 3328 | + | |
3315 | 3329 |
| |
3316 | 3330 |
| |
3317 | 3331 |
| |
| |||
3322 | 3336 |
| |
3323 | 3337 |
| |
3324 | 3338 |
| |
3325 |
| - | |
| 3339 | + | |
| 3340 | + | |
| 3341 | + | |
| 3342 | + | |
| 3343 | + | |
| 3344 | + | |
| 3345 | + | |
| 3346 | + | |
| 3347 | + | |
3326 | 3348 |
| |
3327 |
| - | |
3328 |
| - | |
3329 |
| - | |
3330 | 3349 |
| |
3331 |
| - | |
3332 |
| - | |
| 3350 | + | |
| 3351 | + | |
3333 | 3352 |
| |
3334 |
| - | |
3335 |
| - | |
3336 |
| - | |
3337 |
| - | |
3338 |
| - | |
| 3353 | + | |
| 3354 | + | |
| 3355 | + | |
| 3356 | + | |
3339 | 3357 |
| |
3340 | 3358 |
| |
3341 | 3359 |
| |
| |||
3350 | 3368 |
| |
3351 | 3369 |
| |
3352 | 3370 |
| |
3353 |
| - | |
| 3371 | + | |
3354 | 3372 |
| |
3355 | 3373 |
| |
3356 | 3374 |
| |
|
Lines changed: 29 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
106 | 106 |
| |
107 | 107 |
| |
108 | 108 |
| |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
109 | 138 |
| |
110 | 139 |
| |
111 | 140 |
| |
|
0 commit comments
Comments
(0)