1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-21 02:52:47 +03:00

Fix reset of incorrect hash iterator in GROUPING SETS queries

This fixes an unlikely issue when fetching GROUPING SET results from
their internally stored hash tables.  It was possible in rare cases that
the hash iterator would be set up incorrectly which could result in a
crash.

This was introduced in 4d143509c, so backpatch to v18.

Many thanks to Yuri Zamyatin for reporting and helping to debug this
issue.

Bug: #19078
Reported-by: Yuri Zamyatin <yuri@yrz.am>
Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Jeff Davis <pgsql@j-davis.com>
Discussion: https://postgr.es/m/19078-dfd62f840a2c0766@postgresql.org
Backpatch-through: 18
This commit is contained in:
David Rowley
2025-10-18 16:07:04 +13:00
parent 86d118f9a6
commit 5c0a20003b
2 changed files with 5 additions and 1 deletions

View File

@@ -2911,7 +2911,7 @@ agg_retrieve_hash_table_in_memory(AggState *aggstate)
perhash = &aggstate->perhash[aggstate->current_set];
ResetTupleHashIterator(hashtable, &perhash->hashiter);
ResetTupleHashIterator(perhash->hashtable, &perhash->hashiter);
continue;
}

View File

@@ -1044,6 +1044,10 @@ SH_START_ITERATE_AT(SH_TYPE * tb, SH_ITERATOR * iter, uint32 at)
SH_SCOPE SH_ELEMENT_TYPE *
SH_ITERATE(SH_TYPE * tb, SH_ITERATOR * iter)
{
/* validate sanity of the given iterator */
Assert(iter->cur < tb->size);
Assert(iter->end < tb->size);
while (!iter->done)
{
SH_ELEMENT_TYPE *elem;