mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-24 18:55:04 +08:00
Need defense against oversize index entries in btree CREATE INDEX,
as well as when inserting entries into an existing index.
This commit is contained in:
parent
8da88a6f2b
commit
b79e75d66f
@ -27,7 +27,7 @@
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.47 1999/10/17 22:15:04 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.48 2000/01/08 21:24:49 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -301,6 +301,23 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti, int flags)
|
||||
pgspc = PageGetFreeSpace(npage);
|
||||
btisz = BTITEMSZ(bti);
|
||||
btisz = MAXALIGN(btisz);
|
||||
|
||||
/*
|
||||
* Check whether the item can fit on a btree page at all.
|
||||
* (Eventually, we ought to try to apply TOAST methods if not.)
|
||||
* We actually need to be able to fit three items on every page,
|
||||
* so restrict any one item to 1/3 the per-page available space.
|
||||
* Note that at this point, btisz doesn't include the ItemId.
|
||||
*
|
||||
* NOTE: similar code appears in _bt_insertonpg() to defend against
|
||||
* oversize items being inserted into an already-existing index.
|
||||
* But during creation of an index, we don't go through there.
|
||||
*/
|
||||
if (btisz > (PageGetPageSize(npage)-sizeof(PageHeaderData)-MAXALIGN(sizeof(BTPageOpaqueData)))/3 - sizeof(ItemIdData))
|
||||
elog(ERROR, "btree: index item size %d exceeds maximum %d",
|
||||
btisz,
|
||||
(PageGetPageSize(npage)-sizeof(PageHeaderData)-MAXALIGN(sizeof(BTPageOpaqueData)))/3 - sizeof(ItemIdData));
|
||||
|
||||
if (pgspc < btisz)
|
||||
{
|
||||
Buffer obuf = nbuf;
|
||||
|
Loading…
Reference in New Issue
Block a user