Skip to content

Commit d16e84b

Browse files
committed
Fix ptrack map array index overflow when doing ptrackCheckpoint().
1 parent f490518 commit d16e84b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

engine.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ ptrackCheckpoint(void)
337337
XLogRecPtr init_lsn;
338338
pg_atomic_uint64 buf[PTRACK_BUF_SIZE];
339339
struct stat stat_buf;
340-
int i = 0;
341-
int j = 0;
340+
uint64 i = 0;
341+
uint64 j = 0;
342342

343343
elog(DEBUG1, "ptrack checkpoint");
344344

@@ -430,14 +430,16 @@ ptrackCheckpoint(void)
430430

431431
if (j == PTRACK_BUF_SIZE)
432432
{
433-
int writesz = sizeof(buf);
433+
int writesz = sizeof(buf); /* Up to ~2 GB for buffer size seems
434+
* to be more than enough, so never
435+
* going to overflow. */
434436

435437
/*
436438
* We should not have any allignment issues here, since sizeof()
437439
* takes into account all paddings for us.
438440
*/
439441
ptrack_write_chunk(ptrack_tmp_fd, &crc, (char *) buf, writesz);
440-
elog(DEBUG5, "ptrack checkpoint: i %d, j %d, writesz %d PtrackContentNblocks " UINT64_FORMAT,
442+
elog(DEBUG5, "ptrack checkpoint: i " UINT64_FORMAT ", j " UINT64_FORMAT ", writesz %d PtrackContentNblocks " UINT64_FORMAT,
441443
i, j, writesz, (uint64) PtrackContentNblocks);
442444

443445
j = 0;
@@ -450,7 +452,7 @@ ptrackCheckpoint(void)
450452
int writesz = sizeof(pg_atomic_uint64) * j;
451453

452454
ptrack_write_chunk(ptrack_tmp_fd, &crc, (char *) buf, writesz);
453-
elog(DEBUG5, "ptrack checkpoint: final i %d, j %d, writesz %d PtrackContentNblocks " UINT64_FORMAT,
455+
elog(DEBUG5, "ptrack checkpoint: final i " UINT64_FORMAT ", j " UINT64_FORMAT ", writesz %d PtrackContentNblocks " UINT64_FORMAT,
454456
i, j, writesz, (uint64) PtrackContentNblocks);
455457
}
456458

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