- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit299d171
committed
Install defenses against overflow in BuildTupleHashTable().
The planner can sometimes compute very large values for numGroups, and incases where we have no alternative to building a hashtable, such a valuewill get fed directly to BuildTupleHashTable as its nbuckets parameter.There were two ways in which that could go bad. First, BuildTupleHashTabledeclared the parameter as "int" but most callers were passing "long"s,so on 64-bit machines undetected overflow could occur leading to a bogusnegative value. The obvious fix for that is to change the parameter to"long", which is what I've done in HEAD. In the back branches that seems abit risky, though, since third-party code might be calling this function.So for them, just put in a kluge to treat negative inputs as INT_MAX.Second, hash_create can go nuts with extremely large requested table sizes(notably, my_log2 becomes an infinite loop for inputs larger thanLONG_MAX/2). What seems most appropriate to avoid that is to bound theinitial table size request to work_mem.This fixes bug #6035 reported by Daniel Schreiber. Although the reportedcase only occurs back to 8.4 since it involves WITH RECURSIVE, I thinkit's a good idea to install the defenses in all supported branches.1 parenta9b6519 commit299d171
File tree
3 files changed
+9
-5
lines changed- src
- backend/executor
- include/executor
3 files changed
+9
-5
lines changedLines changed: 6 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
19 | 19 |
| |
20 | 20 |
| |
21 | 21 |
| |
| 22 | + | |
22 | 23 |
| |
23 | 24 |
| |
24 | 25 |
| |
| |||
276 | 277 |
| |
277 | 278 |
| |
278 | 279 |
| |
279 |
| - | |
| 280 | + | |
280 | 281 |
| |
281 | 282 |
| |
282 | 283 |
| |
| |||
285 | 286 |
| |
286 | 287 |
| |
287 | 288 |
| |
| 289 | + | |
| 290 | + | |
| 291 | + | |
288 | 292 |
| |
289 | 293 |
| |
290 | 294 |
| |
| |||
306 | 310 |
| |
307 | 311 |
| |
308 | 312 |
| |
309 |
| - | |
| 313 | + | |
310 | 314 |
| |
311 | 315 |
| |
312 | 316 |
| |
|
Lines changed: 2 additions & 2 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
432 | 432 |
| |
433 | 433 |
| |
434 | 434 |
| |
435 |
| - | |
| 435 | + | |
436 | 436 |
| |
437 | 437 |
| |
438 | 438 |
| |
| |||
458 | 458 |
| |
459 | 459 |
| |
460 | 460 |
| |
461 |
| - | |
| 461 | + | |
462 | 462 |
| |
463 | 463 |
| |
464 | 464 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
131 | 131 |
| |
132 | 132 |
| |
133 | 133 |
| |
134 |
| - | |
| 134 | + | |
135 | 135 |
| |
136 | 136 |
| |
137 | 137 |
| |
|
0 commit comments
Comments
(0)