Skip to content

Commit 33b06a2

Browse files
committed
Fix possible Assert failure in verify_compact_attribute()
Sometimes the TupleDesc used in verify_compact_attribute() is shared among backends, and since CompactAttribute.attcacheoff gets updated during tuple deformation, it was possible that another backend would set attcacheoff on a given CompactAttribute in the small window of time from when the attcacheoff from the live CompactAttribute was being set in the 'tmp' CompactAttribute and before the Assert verifying that the live and tmp CompactAttributes matched. Here we adjust the code to make a copy of the live CompactAttribute so that we're not trying to Assert against a shared copy of it. Author: David Rowley <dgrowleyml@gmail.com> Reported-by: Alexander Lakhin <exclusion@gmail.com> Discussion: https://postgr.es/m/7195e408-758c-4031-8e61-4f842c716ac0@gmail.com
1 parent e9a3615 commit 33b06a2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/backend/access/common/tupdesc.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,17 @@ void
142142
verify_compact_attribute(TupleDesc tupdesc, int attnum)
143143
{
144144
#ifdef USE_ASSERT_CHECKING
145-
CompactAttribute *cattr = &tupdesc->compact_attrs[attnum];
145+
CompactAttribute cattr;
146146
Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum);
147147
CompactAttribute tmp;
148148

149+
/*
150+
* Make a temp copy of the TupleDesc's CompactAttribute. This may be a
151+
* shared TupleDesc and the attcacheoff might get changed by another
152+
* backend.
153+
*/
154+
memcpy(&cattr, &tupdesc->compact_attrs[attnum], sizeof(CompactAttribute));
155+
149156
/*
150157
* Populate the temporary CompactAttribute from the corresponding
151158
* Form_pg_attribute
@@ -156,11 +163,11 @@ verify_compact_attribute(TupleDesc tupdesc, int attnum)
156163
* Make the attcacheoff match since it's been reset to -1 by
157164
* populate_compact_attribute_internal. Same with attnullability.
158165
*/
159-
tmp.attcacheoff = cattr->attcacheoff;
160-
tmp.attnullability = cattr->attnullability;
166+
tmp.attcacheoff = cattr.attcacheoff;
167+
tmp.attnullability = cattr.attnullability;
161168

162169
/* Check the freshly populated CompactAttribute matches the TupleDesc's */
163-
Assert(memcmp(&tmp, cattr, sizeof(CompactAttribute)) == 0);
170+
Assert(memcmp(&tmp, &cattr, sizeof(CompactAttribute)) == 0);
164171
#endif
165172
}
166173

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy