Skip to content

Commit 8f40d46

Browse files
committed
Fix off_t overflow in pg_basebackup on Windows.
walmethods.c used off_t to navigate around a pg_wal.tar file that could exceed 2GB, which doesn't work on Windows and would fail with misleading errors. Use pgoff_t instead. Back-patch to all supported branches. Author: Davinder Singh <davinder.singh@enterprisedb.com> Reported-by: Jakub Wartak <jakub.wartak@enterprisedb.com> Discussion: https://postgr.es/m/CAKZiRmyM4YnokK6Oenw5JKwAQ3rhP0YTz2T-tiw5dAQjGRXE3Q%40mail.gmail.com
1 parent 1636c5e commit 8f40d46

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/bin/pg_basebackup/receivelog.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ open_walfile(StreamCtl *stream, XLogRecPtr startpoint)
190190
static bool
191191
close_walfile(StreamCtl *stream, XLogRecPtr pos)
192192
{
193-
off_t currpos;
193+
pgoff_t currpos;
194194
int r;
195195

196196
if (walfile == NULL)

src/bin/pg_basebackup/walmethods.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static DirectoryMethodData *dir_data = NULL;
5555
typedef struct DirectoryMethodFile
5656
{
5757
int fd;
58-
off_t currpos;
58+
pgoff_t currpos;
5959
char *pathname;
6060
char *fullpath;
6161
char *temp_suffix;
@@ -241,7 +241,7 @@ dir_write(Walfile f, const void *buf, size_t count)
241241
return r;
242242
}
243243

244-
static off_t
244+
static pgoff_t
245245
dir_get_current_pos(Walfile f)
246246
{
247247
Assert(f != NULL);
@@ -468,8 +468,8 @@ FreeWalDirectoryMethod(void)
468468

469469
typedef struct TarMethodFile
470470
{
471-
off_t ofs_start; /* Where does the *header* for this file start */
472-
off_t currpos;
471+
pgoff_t ofs_start; /* Where does the *header* for this file start */
472+
pgoff_t currpos;
473473
char header[TAR_BLOCK_SIZE];
474474
char *pathname;
475475
size_t pad_to_size;
@@ -801,7 +801,7 @@ tar_compression(void)
801801
return tar_data->compression;
802802
}
803803

804-
static off_t
804+
static pgoff_t
805805
tar_get_current_pos(Walfile f)
806806
{
807807
Assert(f != NULL);

src/bin/pg_basebackup/walmethods.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct WalWriteMethod
6868
ssize_t (*write) (Walfile f, const void *buf, size_t count);
6969

7070
/* Return the current position in a file or -1 on error */
71-
off_t (*get_current_pos) (Walfile f);
71+
pgoff_t (*get_current_pos) (Walfile f);
7272

7373
/*
7474
* fsync the contents of the specified file. Returns 0 on success.

0 commit comments

Comments
 (0)