Commit b79e75d6 authored by Tom Lane's avatar Tom Lane

Need defense against oversize index entries in btree CREATE INDEX,

as well as when inserting entries into an existing index.
parent 8da88a6f
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* Copyright (c) 1994, Regents of the University of California * Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * 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) ...@@ -301,6 +301,23 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti, int flags)
pgspc = PageGetFreeSpace(npage); pgspc = PageGetFreeSpace(npage);
btisz = BTITEMSZ(bti); btisz = BTITEMSZ(bti);
btisz = MAXALIGN(btisz); 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) if (pgspc < btisz)
{ {
Buffer obuf = nbuf; Buffer obuf = nbuf;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment