Skip to content

Commit

Permalink
Fix potential int overflow in merge chunks
Browse files Browse the repository at this point in the history
When merging chunks, a relation size calculation could potentially
overflow an 32-bit integer value. Use a 64-bit integer for the result
to prevent overflow.
  • Loading branch information
erimatnor committed Jan 20, 2025
1 parent 08050fb commit 6f2aa30
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tsl/src/chunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <access/tableam.h>
#include <access/transam.h>
#include <access/xact.h>
#include <c.h>
#include <catalog/catalog.h>
#include <catalog/dependency.h>
#include <catalog/heap.h>
Expand Down Expand Up @@ -661,8 +662,10 @@ static TableAmRoutine routine = {};
static uint64
pq17_workaround_merge_relation_size(Relation rel, ForkNumber forkNumber)
{
uint64 nblocks = merge_rel_nblocks;

if (forkNumber == MAIN_FORKNUM)
return merge_rel_nblocks * BLCKSZ;
return nblocks * BLCKSZ;

return old_routine->relation_size(rel, forkNumber);
}
Expand Down

0 comments on commit 6f2aa30

Please sign in to comment.