forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit9fe285f
committed
Preserve memory context of VarStringSortSupport buffers.
When enlarging the work buffers of a VarStringSortSupport object,varstrfastcmp_locale was careful to keep them in the ssup_cxtmemory context; but varstr_abbrev_convert just used palloc().The latter creates a hazard that the buffers could be freed outfrom under the VarStringSortSupport object, resulting in stompingon whatever gets allocated in that memory later.In practice, because we only use this code for ICU collations(cf.3df9c37), the problem is confined to use of ICU collations.I believe it may have been unreachable before the introductionof incremental sort, too, as traditional sorting usually justuses one context for the duration of the sort.We could fix this by making the broken stanzas in varstr_abbrev_convertmatch the non-broken ones in varstrfastcmp_locale. However, it seemslike a better idea to dodge the issue altogether by replacing thepfree-and-allocate-anew coding with repalloc, which automaticallypreserves the chunk's memory context. This fix does add a few cyclesbecause repalloc will copy the chunk's content, which the existingcoding assumes is useless. However, we don't expect that these bufferenlargement operations are performance-critical. Besides that, it'sfar from obvious that copying the buffer contents isn't required, sincethese stanzas make no effort to mark the buffers invalid by resettinglast_returned, cache_blob, etc. That seems to be safe upon examination,but it's fragile and could easily get broken in future, which wouldn'tget revealed in testing with short-to-moderate-size strings.Per bug #17584 from James Inform. Whether or not the issue isreachable in the older branches, this code has been broken on itsown terms from its introduction, so patch all the way back.Discussion:https://postgr.es/m/17584-95c79b4a7d771f44@postgresql.org1 parent4878ea7 commit9fe285f
1 file changed
+6
-10
lines changedLines changed: 6 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
78 | 78 |
| |
79 | 79 |
| |
80 | 80 |
| |
81 |
| - | |
82 |
| - | |
| 81 | + | |
| 82 | + | |
83 | 83 |
| |
84 | 84 |
| |
85 | 85 |
| |
| |||
2309 | 2309 |
| |
2310 | 2310 |
| |
2311 | 2311 |
| |
2312 |
| - | |
2313 | 2312 |
| |
2314 |
| - | |
| 2313 | + | |
2315 | 2314 |
| |
2316 | 2315 |
| |
2317 | 2316 |
| |
2318 |
| - | |
2319 | 2317 |
| |
2320 |
| - | |
| 2318 | + | |
2321 | 2319 |
| |
2322 | 2320 |
| |
2323 | 2321 |
| |
| |||
2518 | 2516 |
| |
2519 | 2517 |
| |
2520 | 2518 |
| |
2521 |
| - | |
2522 | 2519 |
| |
2523 |
| - | |
| 2520 | + | |
2524 | 2521 |
| |
2525 | 2522 |
| |
2526 | 2523 |
| |
| |||
2607 | 2604 |
| |
2608 | 2605 |
| |
2609 | 2606 |
| |
2610 |
| - | |
2611 | 2607 |
| |
2612 | 2608 |
| |
2613 |
| - | |
| 2609 | + | |
2614 | 2610 |
| |
2615 | 2611 |
| |
2616 | 2612 |
| |
|
0 commit comments
Comments
(0)