forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit019a40d
committed
intarray: Prevent out-of-bound memory reads with gist__int_ops
As gist__int_ops stands in intarray, it is possible to store GiSTentries for leaf pages that can cause corruptions when decompressed.Leaf nodes are stored as decompressed all the time by the compressionmethod, and the decompression method should map with that, retrievingthe contents of the page without doing any decompression. However, thecode authorized the insertion of leaf page data with a higher number ofarray items than what can be supported, generating a NOTICE message toinform about this matter (199 for a 8k page, for reference). Whencalling the decompression method, a decompression would be attempted onthis leaf node item but the contents should be retrieved as they are.The NOTICE message generated when dealing with the compression of a leafpage and too many elements in the input array for gist__int_ops has beenintroduced by08ee64e, removing the marker stored in the array to trackif this is actually a leaf node. However, it also missed the fact thatthe decompression path should do nothing for a leaf page. Hence, as thecode stand, a too-large array would be stored as uncompressed but thedecompression path would attempt a decompression rather that retrievingthe contents as they are.This leads to various problems. First, even if08ee64e tried to addressthat, it is possible to do out-of-bound chunk writes with a large inputarray, with the backend informing about that with WARNINGs. Ondecompression, retrieving the stored leaf data would lead to incorrectmemory reads, leading to crashes or even worse.Perhaps somebody would be interested in expanding the number of arrayitems that can be handled in a leaf page for this operator in thefuture, which would require revisiting the choice done in08ee64e, butbased on the lack of reports about this problem since 2005 it does notlook so. For now, this commit prevents the insertion of data for leafpages when using more array items that the code can handle ondecompression, switching the NOTICE message to an ERROR. If one wishesto use more array items, gist__intbig_ops is an optional choice.While on it, use ERRCODE_PROGRAM_LIMIT_EXCEEDED as error code when alimit is reached, because that's what the module is facing in suchcases.Author: Ankit Kumar Pandey, Alexander LakhinReviewed-by: Richard Guo, Michael PaquierDiscussion:https://postgr.es/m/796b65c3-57b7-bddf-b0d5-a8afafb8b627@gmail.comDiscussion:https://postgr.es/m/17888-f72930e6b5ce8c14@postgresql.orgBackpatch-through: 111 parentd1423c5 commit019a40d
3 files changed
+12
-4
lines changedLines changed: 8 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
180 | 180 |
| |
181 | 181 |
| |
182 | 182 |
| |
183 |
| - | |
184 |
| - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
185 | 187 |
| |
186 | 188 |
| |
187 | 189 |
| |
| |||
269 | 271 |
| |
270 | 272 |
| |
271 | 273 |
| |
272 |
| - | |
| 274 | + | |
| 275 | + | |
273 | 276 |
| |
274 | 277 |
| |
275 | 278 |
| |
| |||
331 | 334 |
| |
332 | 335 |
| |
333 | 336 |
| |
334 |
| - | |
| 337 | + | |
| 338 | + | |
335 | 339 |
| |
336 | 340 |
| |
337 | 341 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
547 | 547 |
| |
548 | 548 |
| |
549 | 549 |
| |
| 550 | + | |
| 551 | + | |
550 | 552 |
| |
551 | 553 |
| |
552 | 554 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
110 | 110 |
| |
111 | 111 |
| |
112 | 112 |
| |
| 113 | + | |
| 114 | + | |
113 | 115 |
| |
114 | 116 |
| |
115 | 117 |
| |
|
0 commit comments
Comments
(0)