Skip to content

Commit d94cf5c

Browse files
committed
File size in a backup manifest should use uint64, not size_t.
size_t is the size of an object in memory, not the size of a file on disk. Thanks to Tom Lane for noting the error. Discussion: http://postgr.es/m/1865585.1727803933@sss.pgh.pa.us
1 parent 7b2822e commit d94cf5c

File tree

9 files changed

+28
-22
lines changed

9 files changed

+28
-22
lines changed

src/bin/pg_combinebackup/load_manifest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void combinebackup_version_cb(JsonManifestParseContext *context,
6060
static void combinebackup_system_identifier_cb(JsonManifestParseContext *context,
6161
uint64 manifest_system_identifier);
6262
static void combinebackup_per_file_cb(JsonManifestParseContext *context,
63-
const char *pathname, size_t size,
63+
const char *pathname, uint64 size,
6464
pg_checksum_type checksum_type,
6565
int checksum_length,
6666
uint8 *checksum_payload);
@@ -267,7 +267,7 @@ combinebackup_system_identifier_cb(JsonManifestParseContext *context,
267267
*/
268268
static void
269269
combinebackup_per_file_cb(JsonManifestParseContext *context,
270-
const char *pathname, size_t size,
270+
const char *pathname, uint64 size,
271271
pg_checksum_type checksum_type,
272272
int checksum_length, uint8 *checksum_payload)
273273
{

src/bin/pg_combinebackup/load_manifest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ typedef struct manifest_file
2323
{
2424
uint32 status; /* hash status */
2525
const char *pathname;
26-
size_t size;
26+
uint64 size;
2727
pg_checksum_type checksum_type;
2828
int checksum_length;
2929
uint8 *checksum_payload;

src/bin/pg_combinebackup/write_manifest.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ create_manifest_writer(char *directory, uint64 system_identifier)
7474
*/
7575
void
7676
add_file_to_manifest(manifest_writer *mwriter, const char *manifest_path,
77-
size_t size, time_t mtime,
77+
uint64 size, time_t mtime,
7878
pg_checksum_type checksum_type,
7979
int checksum_length,
8080
uint8 *checksum_payload)
@@ -104,7 +104,8 @@ add_file_to_manifest(manifest_writer *mwriter, const char *manifest_path,
104104
appendStringInfoString(&mwriter->buf, "\", ");
105105
}
106106

107-
appendStringInfo(&mwriter->buf, "\"Size\": %zu, ", size);
107+
appendStringInfo(&mwriter->buf, "\"Size\": %llu, ",
108+
(unsigned long long) size);
108109

109110
appendStringInfoString(&mwriter->buf, "\"Last-Modified\": \"");
110111
enlargeStringInfo(&mwriter->buf, 128);

src/bin/pg_combinebackup/write_manifest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern manifest_writer *create_manifest_writer(char *directory,
2323
uint64 system_identifier);
2424
extern void add_file_to_manifest(manifest_writer *mwriter,
2525
const char *manifest_path,
26-
size_t size, time_t mtime,
26+
uint64 size, time_t mtime,
2727
pg_checksum_type checksum_type,
2828
int checksum_length,
2929
uint8 *checksum_payload);

src/bin/pg_verifybackup/astreamer_verify.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ member_verify_header(astreamer *streamer, astreamer_member *member)
207207
if (m->size != member->size)
208208
{
209209
report_backup_error(mystreamer->context,
210-
"\"%s\" has size %lld in \"%s\" but size %zu in the manifest",
211-
member->pathname, (long long int) member->size,
212-
mystreamer->archive_name, m->size);
210+
"\"%s\" has size %llu in \"%s\" but size %llu in the manifest",
211+
member->pathname,
212+
(unsigned long long) member->size,
213+
mystreamer->archive_name,
214+
(unsigned long long) m->size);
213215
m->bad = true;
214216
return;
215217
}
@@ -294,9 +296,10 @@ member_verify_checksum(astreamer *streamer)
294296
if (mystreamer->checksum_bytes != m->size)
295297
{
296298
report_backup_error(mystreamer->context,
297-
"file \"%s\" in \"%s\" should contain %zu bytes, but read %zu bytes",
299+
"file \"%s\" in \"%s\" should contain %llu bytes, but read %llu bytes",
298300
m->pathname, mystreamer->archive_name,
299-
m->size, mystreamer->checksum_bytes);
301+
(unsigned long long) m->size,
302+
(unsigned long long) mystreamer->checksum_bytes);
300303
return;
301304
}
302305

src/bin/pg_verifybackup/pg_verifybackup.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static void verifybackup_version_cb(JsonManifestParseContext *context,
6161
static void verifybackup_system_identifier(JsonManifestParseContext *context,
6262
uint64 manifest_system_identifier);
6363
static void verifybackup_per_file_cb(JsonManifestParseContext *context,
64-
const char *pathname, size_t size,
64+
const char *pathname, uint64 size,
6565
pg_checksum_type checksum_type,
6666
int checksum_length,
6767
uint8 *checksum_payload);
@@ -547,7 +547,7 @@ verifybackup_system_identifier(JsonManifestParseContext *context,
547547
*/
548548
static void
549549
verifybackup_per_file_cb(JsonManifestParseContext *context,
550-
const char *pathname, size_t size,
550+
const char *pathname, uint64 size,
551551
pg_checksum_type checksum_type,
552552
int checksum_length, uint8 *checksum_payload)
553553
{
@@ -719,8 +719,9 @@ verify_plain_backup_file(verifier_context *context, char *relpath,
719719
if (m->size != sb.st_size)
720720
{
721721
report_backup_error(context,
722-
"\"%s\" has size %lld on disk but size %zu in the manifest",
723-
relpath, (long long int) sb.st_size, m->size);
722+
"\"%s\" has size %llu on disk but size %llu in the manifest",
723+
relpath, (unsigned long long) sb.st_size,
724+
(unsigned long long) m->size);
724725
m->bad = true;
725726
}
726727

@@ -1101,7 +1102,7 @@ verify_file_checksum(verifier_context *context, manifest_file *m,
11011102
const char *relpath = m->pathname;
11021103
int fd;
11031104
int rc;
1104-
size_t bytes_read = 0;
1105+
uint64 bytes_read = 0;
11051106
uint8 checksumbuf[PG_CHECKSUM_MAX_LENGTH];
11061107
int checksumlen;
11071108

@@ -1164,8 +1165,9 @@ verify_file_checksum(verifier_context *context, manifest_file *m,
11641165
if (bytes_read != m->size)
11651166
{
11661167
report_backup_error(context,
1167-
"file \"%s\" should contain %zu bytes, but read %zu bytes",
1168-
relpath, m->size, bytes_read);
1168+
"file \"%s\" should contain %llu bytes, but read %llu bytes",
1169+
relpath, (unsigned long long) m->size,
1170+
(unsigned long long) bytes_read);
11691171
return;
11701172
}
11711173

src/bin/pg_verifybackup/pg_verifybackup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ typedef struct manifest_file
2929
{
3030
uint32 status; /* hash status */
3131
const char *pathname;
32-
size_t size;
32+
uint64 size;
3333
pg_checksum_type checksum_type;
3434
int checksum_length;
3535
uint8 *checksum_payload;

src/common/parse_manifest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ static void
650650
json_manifest_finalize_file(JsonManifestParseState *parse)
651651
{
652652
JsonManifestParseContext *context = parse->context;
653-
size_t size;
653+
uint64 size;
654654
char *ep;
655655
int checksum_string_length;
656656
pg_checksum_type checksum_type;
@@ -688,7 +688,7 @@ json_manifest_finalize_file(JsonManifestParseState *parse)
688688
}
689689

690690
/* Parse size. */
691-
size = strtoul(parse->size, &ep, 10);
691+
size = strtou64(parse->size, &ep, 10);
692692
if (*ep)
693693
json_manifest_parse_failure(parse->context,
694694
"file size is not an integer");

src/include/common/parse_manifest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ typedef void (*json_manifest_system_identifier_callback) (JsonManifestParseConte
2828
uint64 manifest_system_identifier);
2929
typedef void (*json_manifest_per_file_callback) (JsonManifestParseContext *,
3030
const char *pathname,
31-
size_t size, pg_checksum_type checksum_type,
31+
uint64 size, pg_checksum_type checksum_type,
3232
int checksum_length, uint8 *checksum_payload);
3333
typedef void (*json_manifest_per_wal_range_callback) (JsonManifestParseContext *,
3434
TimeLineID tli,

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