Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit273dcd1

Browse files
committed
Ensure 64bit arithmetic when calculating tapeSpace
In tuplesort.c:inittapes(), we calculate tapeSpace by first figuringout how many 'tapes' we can use (maxTapes) and then multiplying theresult by the tape buffer overhead for each. Unfortunately, whenwe are on a system with an 8-byte long, we allow work_mem to belarger than 2GB and that allows maxTapes to be large enough that the32bit arithmetic can overflow when multiplied against the bufferoverhead.When this overflow happens, we end up adding the overflow to theamount of space available, causing the amount of memory allocated tobe larger than work_mem.Note that to reach this point, you have to set work mem to at least24GB and be sorting a set which is at least that size. Given that auser who can set work_mem to 24GB could also set it even higher, ifthey were looking to run the system out of memory, this isn'tconsidered a security issue.This overflow risk was found by the Coverity scanner.Back-patch to all supported branches, as this issue has existedsince before 8.4.
1 parent1f75a5f commit273dcd1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎src/backend/utils/sort/tuplesort.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ inittapes(Tuplesortstate *state)
17881788
* account for tuple space, so we don't care if LACKMEM becomes
17891789
* inaccurate.)
17901790
*/
1791-
tapeSpace=maxTapes*TAPE_BUFFER_OVERHEAD;
1791+
tapeSpace=(int64)maxTapes*TAPE_BUFFER_OVERHEAD;
17921792
if (tapeSpace+GetMemoryChunkSpace(state->memtuples)<state->allowedMem)
17931793
USEMEM(state,tapeSpace);
17941794

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp