forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit757c518
committed
Avoid crashes in contrib/intarray gist__int_ops (bug #15518)
1. Integer overflow in internal_size could result in memory corruptionin decompression since a zero-length array would be allocated and thenwritten to. This leads to crashes or corruption when traversing anindex which has been populated with sufficiently sparse values. Fix byusing int64 for computations and checking for overflow.2. Integer overflow in g_int_compress could cause pessimal mergechoices, resulting in unnecessarily large ranges (which would in turntrigger issue 1 above). Fix by using int64 again.3. Even without overflow, array sizes could become large enough tocause unexplained memory allocation errors. Fix by capping the sizesto a safe limit and report actual errors pointing at gist__intbig_opsas needed.4. Large inputs to the compression function always consist of largeruns of consecutive integers, and the compression loop was processingthese one at a time in an O(N^2) manner with a lot of overhead. Theexpected runtime of this function could easily exceed 6 months for asingle call as a result. Fix by performing a linear-time first pass,which reduces the worst case to something on the order of seconds.Backpatch all the way, since this has been wrong forever.Per bug #15518 from report from irc user "dymk", analysis and patch byme.Discussion:https://postgr.es/m/15518-799e426c3b4f8358@postgresql.org1 parent452b637 commit757c518
2 files changed
+73
-12
lines changedLines changed: 63 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
12 | 12 |
| |
13 | 13 |
| |
14 | 14 |
| |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
15 | 26 |
| |
16 | 27 |
| |
17 | 28 |
| |
| |||
141 | 152 |
| |
142 | 153 |
| |
143 | 154 |
| |
144 |
| - | |
| 155 | + | |
| 156 | + | |
145 | 157 |
| |
146 | 158 |
| |
147 |
| - | |
| 159 | + | |
148 | 160 |
| |
| 161 | + | |
149 | 162 |
| |
150 | 163 |
| |
151 | 164 |
| |
| |||
186 | 199 |
| |
187 | 200 |
| |
188 | 201 |
| |
189 |
| - | |
190 |
| - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
191 | 225 |
| |
192 |
| - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
193 | 237 |
| |
194 | 238 |
| |
195 | 239 |
| |
196 |
| - | |
| 240 | + | |
197 | 241 |
| |
198 |
| - | |
| 242 | + | |
199 | 243 |
| |
200 |
| - | |
| 244 | + | |
201 | 245 |
| |
202 | 246 |
| |
203 | 247 |
| |
204 | 248 |
| |
205 | 249 |
| |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
206 | 258 |
| |
207 | 259 |
| |
208 | 260 |
| |
| |||
260 | 312 |
| |
261 | 313 |
| |
262 | 314 |
| |
| 315 | + | |
| 316 | + | |
| 317 | + | |
263 | 318 |
| |
264 | 319 |
| |
265 | 320 |
| |
|
Lines changed: 10 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3 | 3 |
| |
4 | 4 |
| |
5 | 5 |
| |
| 6 | + | |
| 7 | + | |
6 | 8 |
| |
7 | 9 |
| |
8 | 10 |
| |
| |||
225 | 227 |
| |
226 | 228 |
| |
227 | 229 |
| |
| 230 | + | |
228 | 231 |
| |
229 | 232 |
| |
230 | 233 |
| |
| |||
252 | 255 |
| |
253 | 256 |
| |
254 | 257 |
| |
| 258 | + | |
255 | 259 |
| |
256 | 260 |
| |
257 | 261 |
| |
| |||
288 | 292 |
| |
289 | 293 |
| |
290 | 294 |
| |
291 |
| - | |
292 |
| - | |
| 295 | + | |
| 296 | + | |
293 | 297 |
| |
294 | 298 |
| |
295 | 299 |
| |
296 | 300 |
| |
297 |
| - | |
| 301 | + | |
298 | 302 |
| |
299 | 303 |
| |
300 |
| - | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
301 | 307 |
| |
302 | 308 |
| |
303 | 309 |
| |
|
0 commit comments
Comments
(0)