mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Fix pg_restore to accept POSIX-conformant tar files.
Back-patch portions of commit 05b555d12b
.
We need to patch pg_restore to accept either version of the magic string,
in hopes of avoiding compatibility problems when 9.3 comes out. I also
fixed pg_dump to write the correct 2-block EOF marker, since that won't
create a compatibility problem with pg_restore and it could help with some
versions of tar.
Brian Weaver and Tom Lane
This commit is contained in:
@ -873,8 +873,10 @@ _CloseArchive(ArchiveHandle *AH)
|
|||||||
|
|
||||||
tarClose(AH, th);
|
tarClose(AH, th);
|
||||||
|
|
||||||
/* Add a block of NULLs since it's de-rigeur. */
|
/*
|
||||||
for (i = 0; i < 512; i++)
|
* EOF marker for tar files is two blocks of NULLs.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < 512 * 2; i++)
|
||||||
{
|
{
|
||||||
if (fputc(0, ctx->tarFH) == EOF)
|
if (fputc(0, ctx->tarFH) == EOF)
|
||||||
die_horribly(AH, modulename,
|
die_horribly(AH, modulename,
|
||||||
@ -1025,11 +1027,16 @@ _tarChecksum(char *header)
|
|||||||
int i,
|
int i,
|
||||||
sum;
|
sum;
|
||||||
|
|
||||||
sum = 0;
|
/*
|
||||||
|
* Per POSIX, the checksum is the simple sum of all bytes in the header,
|
||||||
|
* treating the bytes as unsigned, and treating the checksum field (at
|
||||||
|
* offset 148) as though it contained 8 spaces.
|
||||||
|
*/
|
||||||
|
sum = 8 * ' '; /* presumed value for checksum field */
|
||||||
for (i = 0; i < 512; i++)
|
for (i = 0; i < 512; i++)
|
||||||
if (i < 148 || i >= 156)
|
if (i < 148 || i >= 156)
|
||||||
sum += 0xFF & header[i];
|
sum += 0xFF & header[i];
|
||||||
return sum + 256; /* Assume 8 blanks in checksum field */
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -1043,11 +1050,15 @@ isValidTarHeader(char *header)
|
|||||||
if (sum != chk)
|
if (sum != chk)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* POSIX format */
|
/* POSIX tar format */
|
||||||
if (strncmp(&header[257], "ustar00", 7) == 0)
|
if (memcmp(&header[257], "ustar\0", 6) == 0 &&
|
||||||
|
memcmp(&header[263], "00", 2) == 0)
|
||||||
return true;
|
return true;
|
||||||
/* older format */
|
/* GNU tar format */
|
||||||
if (strncmp(&header[257], "ustar ", 7) == 0)
|
if (memcmp(&header[257], "ustar \0", 8) == 0)
|
||||||
|
return true;
|
||||||
|
/* not-quite-POSIX format written by pre-9.3 pg_dump */
|
||||||
|
if (memcmp(&header[257], "ustar00\0", 8) == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user