Skip to content

Commit 7157fe8

Browse files
committed
Fix overly-strict assertions in spgtextproc.c.
spg_text_inner_consistent is capable of reconstructing an empty string to pass down to the next index level; this happens if we have an empty string coming in, no prefix, and a dummy node label. (In practice, what is needed to trigger that is insertion of a whole bunch of empty-string values.) Then, we will arrive at the next level with in->level == 0 and a non-NULL (but zero length) in->reconstructedValue, which is valid but the Assert tests weren't expecting it. Per report from Andreas Seltenreich. This has no impact in non-Assert builds, so should not be a problem in production, but back-patch to all affected branches anyway. In passing, remove a couple of useless variable initializations and shorten the code by not duplicating DatumGetPointer() calls.
1 parent df35af2 commit 7157fe8

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/backend/access/spgist/spgtextproc.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,9 @@ spg_text_inner_consistent(PG_FUNCTION_ARGS)
403403
spgInnerConsistentIn *in = (spgInnerConsistentIn *) PG_GETARG_POINTER(0);
404404
spgInnerConsistentOut *out = (spgInnerConsistentOut *) PG_GETARG_POINTER(1);
405405
bool collate_is_c = lc_collate_is_c(PG_GET_COLLATION());
406-
text *reconstrText = NULL;
407-
int maxReconstrLen = 0;
406+
text *reconstructedValue;
407+
text *reconstrText;
408+
int maxReconstrLen;
408409
text *prefixText = NULL;
409410
int prefixSize = 0;
410411
int i;
@@ -420,8 +421,9 @@ spg_text_inner_consistent(PG_FUNCTION_ARGS)
420421
* created by a previous invocation of this routine, and we always emit
421422
* long-format reconstructed values.
422423
*/
423-
Assert(in->level == 0 ? DatumGetPointer(in->reconstructedValue) == NULL :
424-
VARSIZE_ANY_EXHDR(DatumGetPointer(in->reconstructedValue)) == in->level);
424+
reconstructedValue = (text *) DatumGetPointer(in->reconstructedValue);
425+
Assert(reconstructedValue == NULL ? in->level == 0 :
426+
VARSIZE_ANY_EXHDR(reconstructedValue) == in->level);
425427

426428
maxReconstrLen = in->level + 1;
427429
if (in->hasPrefix)
@@ -436,7 +438,7 @@ spg_text_inner_consistent(PG_FUNCTION_ARGS)
436438

437439
if (in->level)
438440
memcpy(VARDATA(reconstrText),
439-
VARDATA(DatumGetPointer(in->reconstructedValue)),
441+
VARDATA(reconstructedValue),
440442
in->level);
441443
if (prefixSize)
442444
memcpy(((char *) VARDATA(reconstrText)) + in->level,
@@ -560,7 +562,7 @@ spg_text_leaf_consistent(PG_FUNCTION_ARGS)
560562
if (DatumGetPointer(in->reconstructedValue))
561563
reconstrValue = DatumGetTextP(in->reconstructedValue);
562564

563-
Assert(level == 0 ? reconstrValue == NULL :
565+
Assert(reconstrValue == NULL ? level == 0 :
564566
VARSIZE_ANY_EXHDR(reconstrValue) == level);
565567

566568
/* Reconstruct the full string represented by this leaf tuple */

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