Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 85c17db

Browse files
committed
Out-of-bounds memory allocation request sizes should be treated as just
elog(ERROR) not an Assert trap, since we've downgraded out-of-memory to elog(ERROR) not a fatal error. Also, change the hard boundary from 256Mb to 1Gb, just so that anyone who's actually got that much memory to spare can play with TOAST objects approaching a gigabyte.
1 parent 192ce19 commit 85c17db

File tree

4 files changed

+14
-25
lines changed

4 files changed

+14
-25
lines changed

src/backend/utils/error/excid.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/excid.c,v 1.9 2001/01/24 19:43:15 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/excid.c,v 1.10 2001/02/06 01:53:53 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -42,18 +42,6 @@ Exception BadArg = {"Bad Argument to Function Call"};
4242
* Specific Recoverable Exceptions *
4343
*****************************************************************************/
4444

45-
/*
46-
* BadAllocSize
47-
* Indicates that an allocation request is of unreasonable size.
48-
*/
49-
Exception BadAllocSize = {"Too Large Allocation Request"};
50-
51-
/*
52-
* ExhaustedMemory
53-
* Indicates an dynamic memory allocation failed.
54-
*/
55-
Exception ExhaustedMemory = {"Memory Allocation Failed"};
56-
5745
/*
5846
* Unimplemented
5947
* Indicates a function call request requires unimplemented code.

src/backend/utils/mmgr/mcxt.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.26 2001/01/24 19:43:16 momjian Exp $
17+
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.27 2001/02/06 01:53:53 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -417,8 +417,9 @@ MemoryContextAlloc(MemoryContext context, Size size)
417417
{
418418
AssertArg(MemoryContextIsValid(context));
419419

420-
LogTrap(!AllocSizeIsValid(size), BadAllocSize,
421-
("size=%d [0x%x]", size, size));
420+
if (!AllocSizeIsValid(size))
421+
elog(ERROR, "MemoryContextAlloc: invalid request size %lu",
422+
(unsigned long) size);
422423

423424
return (*context->methods->alloc) (context, size);
424425
}
@@ -474,8 +475,9 @@ repalloc(void *pointer, Size size)
474475

475476
AssertArg(MemoryContextIsValid(header->context));
476477

477-
LogTrap(!AllocSizeIsValid(size), BadAllocSize,
478-
("size=%d [0x%x]", size, size));
478+
if (!AllocSizeIsValid(size))
479+
elog(ERROR, "repalloc: invalid request size %lu",
480+
(unsigned long) size);
479481

480482
return (*header->context->methods->realloc) (header->context,
481483
pointer, size);

src/include/utils/excid.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: excid.h,v 1.8 2001/01/24 19:43:28 momjian Exp $
10+
* $Id: excid.h,v 1.9 2001/02/06 01:53:52 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -18,8 +18,6 @@
1818
extern Exception FailedAssertion;
1919
extern Exception BadState;
2020
extern Exception BadArg;
21-
extern Exception BadAllocSize;
22-
extern Exception ExhaustedMemory;
2321
extern Exception Unimplemented;
2422

2523
extern Exception CatalogFailure;/* XXX inconsistent naming style */

src/include/utils/memutils.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
13-
* $Id: memutils.h,v 1.41 2001/01/24 19:43:28 momjian Exp $
13+
* $Id: memutils.h,v 1.42 2001/02/06 01:53:52 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -22,16 +22,17 @@
2222

2323
/*
2424
* MaxAllocSize
25-
* Arbitrary limit on size of allocations.
25+
* Quasi-arbitrary limit on size of allocations.
2626
*
2727
* Note:
2828
* There is no guarantee that allocations smaller than MaxAllocSize
2929
* will succeed. Allocation requests larger than MaxAllocSize will
3030
* be summarily denied.
3131
*
32-
* XXX This should be defined in a file of tunable constants.
32+
* XXX This is deliberately chosen to correspond to the limiting size
33+
* of varlena objects under TOAST. See VARATT_MASK_SIZE in postgres.h.
3334
*/
34-
#define MaxAllocSize ((Size) 0xfffffff) /* 16G - 1 */
35+
#define MaxAllocSize ((Size) 0x3fffffff) /* 1 gigabyte - 1 */
3536

3637
#define AllocSizeIsValid(size) (0 < (size) && (size) <= MaxAllocSize)
3738

0 commit comments

Comments
 (0)