Fix off_t overflow in pg_basebackup on Windows.
authorThomas Munro <tmunro@postgresql.org>
Thu, 9 Jan 2025 00:17:36 +0000 (13:17 +1300)
committerThomas Munro <tmunro@postgresql.org>
Thu, 9 Jan 2025 03:05:08 +0000 (16:05 +1300)
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

src/bin/pg_basebackup/receivelog.c
src/bin/pg_basebackup/walmethods.c
src/bin/pg_basebackup/walmethods.h

index 504d82bef67b30ef0a7634e1aae1f8b6b2f36c96..e69ad912a2576ac47025aaba8f3c622eee052ae8 100644 (file)
@@ -192,7 +192,7 @@ static bool
 close_walfile(StreamCtl *stream, XLogRecPtr pos)
 {
    char       *fn;
-   off_t       currpos;
+   pgoff_t     currpos;
    int         r;
    char        walfile_name[MAXPGPATH];
 
index 376ddf72b7104640cede8dd049cbb00ad5e0af28..f21883d30d635f9bec7d753916769863a5353a7d 100644 (file)
@@ -686,7 +686,7 @@ const WalWriteMethodOps WalTarMethodOps = {
 typedef struct TarMethodFile
 {
    Walfile     base;
-   off_t       ofs_start;      /* Where does the *header* for this file start */
+   pgoff_t     ofs_start;      /* Where does the *header* for this file start */
    char        header[TAR_BLOCK_SIZE];
    size_t      pad_to_size;
 } TarMethodFile;
index 54a22fe6070a1105944fc7e2304b6706dceb380c..1ebdd360e64ff6a8e8c094e80a5d057f56128efd 100644 (file)
@@ -17,7 +17,7 @@ typedef struct WalWriteMethod WalWriteMethod;
 typedef struct
 {
    WalWriteMethod *wwmethod;
-   off_t       currpos;
+   pgoff_t     currpos;
    char       *pathname;
 
    /*