83
* Maximum file size for a tar member: The limit inherent in the
84
* format is 2^33-1 bytes (nearly 8 GB). But we don't want to exceed
85
* what we can represent in pgoff_t.
87
#define MAX_TAR_MEMBER_FILELEN (((int64) 1 << Min(33, sizeof(pgoff_t)*8 - 1)) - 1)
1037
1030
int chk = tarChecksum(header);
1039
sscanf(&header[148], "%8o", &sum);
1032
sum = read_tar_number(&header[148], 8);
1041
1034
if (sum != chk)
1075
1068
th->fileLen = ftello(tmp);
1076
1069
fseeko(tmp, 0, SEEK_SET);
1079
* Some compilers will throw a warning knowing this test can never be true
1080
* because pgoff_t can't exceed the compared maximum on their platform.
1082
if (th->fileLen > MAX_TAR_MEMBER_FILELEN)
1083
exit_horribly(modulename, "archive member too large for tar format\n");
1085
1071
_tarWriteHeader(th);
1087
1073
while ((cnt = fread(buf, 1, sizeof(buf), tmp)) > 0)
1249
1234
/* Calc checksum */
1250
1235
chk = tarChecksum(h);
1251
sscanf(&h[148], "%8o", &sum);
1236
sum = read_tar_number(&h[148], 8);
1254
1239
* If the checksum failed, see if it is a null block. If so, silently
1274
sscanf(&h[0], "%99s", tag);
1275
sscanf(&h[124], "%12lo", &ullen);
1276
len = (size_t) ullen;
1259
/* Name field is 100 bytes, might not be null-terminated */
1260
strlcpy(tag, &h[0], 100 + 1);
1262
len = read_tar_number(&h[124], 12);
1281
snprintf(buf, sizeof(buf), INT64_FORMAT, (int64) hPos);
1282
ahlog(AH, 3, "TOC Entry %s at %s (length %lu, checksum %d)\n",
1283
tag, buf, (unsigned long) len, sum);
1268
snprintf(posbuf, sizeof(posbuf), UINT64_FORMAT, (uint64) hPos);
1269
snprintf(lenbuf, sizeof(lenbuf), UINT64_FORMAT, (uint64) len);
1270
ahlog(AH, 3, "TOC Entry %s at %s (length %s, checksum %d)\n",
1271
tag, posbuf, lenbuf, sum);
1286
1274
if (chk != sum)
1290
snprintf(buf, sizeof(buf), INT64_FORMAT, (int64) ftello(ctx->tarFH));
1278
snprintf(posbuf, sizeof(posbuf), UINT64_FORMAT,
1279
(uint64) ftello(ctx->tarFH));
1291
1280
exit_horribly(modulename,
1292
1281
"corrupt tar header found in %s "
1293
1282
"(expected %d, computed %d) file position %s\n",
1294
tag, sum, chk, buf);
1283
tag, sum, chk, posbuf);
1297
1286
th->targetFile = pg_strdup(tag);
1309
tarCreateHeader(h, th->targetFile, NULL, th->fileLen, 0600, 04000, 02000, time(NULL));
1298
tarCreateHeader(h, th->targetFile, NULL, th->fileLen,
1299
0600, 04000, 02000, time(NULL));
1311
1301
/* Now write the completed header. */
1312
1302
if (fwrite(h, 1, 512, th->tarFH) != 512)