v1-0001-Try-to-use-uint64-to-size_t-for-file-sizes.patch

application/octet-stream

Filename: v1-0001-Try-to-use-uint64-to-size_t-for-file-sizes.patch
Type: application/octet-stream
Part: 0
Message: Re: pg_verifybackup: TAR format backup verification

Patch

Format: format-patch
Series: patch v1-0001
Subject: Try to use uint64 to size_t for file sizes.
File+
src/bin/pg_combinebackup/load_manifest.c 2 2
src/bin/pg_combinebackup/load_manifest.h 1 1
src/bin/pg_combinebackup/write_manifest.c 3 2
src/bin/pg_combinebackup/write_manifest.h 1 1
src/bin/pg_verifybackup/astreamer_verify.c 8 5
src/bin/pg_verifybackup/pg_verifybackup.c 9 7
src/bin/pg_verifybackup/pg_verifybackup.h 1 1
src/common/parse_manifest.c 2 2
src/include/common/parse_manifest.h 1 1
From d0f79c4a9cf980a564a68cbc61a4100cab8ad28c Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Tue, 1 Oct 2024 10:23:27 -0400
Subject: [PATCH v1] Try to use uint64 to size_t for file sizes.

---
 src/bin/pg_combinebackup/load_manifest.c   |  4 ++--
 src/bin/pg_combinebackup/load_manifest.h   |  2 +-
 src/bin/pg_combinebackup/write_manifest.c  |  5 +++--
 src/bin/pg_combinebackup/write_manifest.h  |  2 +-
 src/bin/pg_verifybackup/astreamer_verify.c | 13 ++++++++-----
 src/bin/pg_verifybackup/pg_verifybackup.c  | 16 +++++++++-------
 src/bin/pg_verifybackup/pg_verifybackup.h  |  2 +-
 src/common/parse_manifest.c                |  4 ++--
 src/include/common/parse_manifest.h        |  2 +-
 9 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/src/bin/pg_combinebackup/load_manifest.c b/src/bin/pg_combinebackup/load_manifest.c
index be8e6273fcb..3a3ad6c2474 100644
--- a/src/bin/pg_combinebackup/load_manifest.c
+++ b/src/bin/pg_combinebackup/load_manifest.c
@@ -60,7 +60,7 @@ static void combinebackup_version_cb(JsonManifestParseContext *context,
 static void combinebackup_system_identifier_cb(JsonManifestParseContext *context,
 											   uint64 manifest_system_identifier);
 static void combinebackup_per_file_cb(JsonManifestParseContext *context,
-									  const char *pathname, size_t size,
+									  const char *pathname, uint64 size,
 									  pg_checksum_type checksum_type,
 									  int checksum_length,
 									  uint8 *checksum_payload);
@@ -267,7 +267,7 @@ combinebackup_system_identifier_cb(JsonManifestParseContext *context,
  */
 static void
 combinebackup_per_file_cb(JsonManifestParseContext *context,
-						  const char *pathname, size_t size,
+						  const char *pathname, uint64 size,
 						  pg_checksum_type checksum_type,
 						  int checksum_length, uint8 *checksum_payload)
 {
diff --git a/src/bin/pg_combinebackup/load_manifest.h b/src/bin/pg_combinebackup/load_manifest.h
index a96ae12eb8e..8e657179af0 100644
--- a/src/bin/pg_combinebackup/load_manifest.h
+++ b/src/bin/pg_combinebackup/load_manifest.h
@@ -23,7 +23,7 @@ typedef struct manifest_file
 {
 	uint32		status;			/* hash status */
 	const char *pathname;
-	size_t		size;
+	uint64		size;
 	pg_checksum_type checksum_type;
 	int			checksum_length;
 	uint8	   *checksum_payload;
diff --git a/src/bin/pg_combinebackup/write_manifest.c b/src/bin/pg_combinebackup/write_manifest.c
index 369d6d2071c..6fea07e7c64 100644
--- a/src/bin/pg_combinebackup/write_manifest.c
+++ b/src/bin/pg_combinebackup/write_manifest.c
@@ -74,7 +74,7 @@ create_manifest_writer(char *directory, uint64 system_identifier)
  */
 void
 add_file_to_manifest(manifest_writer *mwriter, const char *manifest_path,
-					 size_t size, time_t mtime,
+					 uint64 size, time_t mtime,
 					 pg_checksum_type checksum_type,
 					 int checksum_length,
 					 uint8 *checksum_payload)
@@ -104,7 +104,8 @@ add_file_to_manifest(manifest_writer *mwriter, const char *manifest_path,
 		appendStringInfoString(&mwriter->buf, "\", ");
 	}
 
-	appendStringInfo(&mwriter->buf, "\"Size\": %zu, ", size);
+	appendStringInfo(&mwriter->buf, "\"Size\": %llu, ",
+					 (unsigned long long) size);
 
 	appendStringInfoString(&mwriter->buf, "\"Last-Modified\": \"");
 	enlargeStringInfo(&mwriter->buf, 128);
diff --git a/src/bin/pg_combinebackup/write_manifest.h b/src/bin/pg_combinebackup/write_manifest.h
index ebc4f9441ad..d2becaba1f9 100644
--- a/src/bin/pg_combinebackup/write_manifest.h
+++ b/src/bin/pg_combinebackup/write_manifest.h
@@ -23,7 +23,7 @@ extern manifest_writer *create_manifest_writer(char *directory,
 											   uint64 system_identifier);
 extern void add_file_to_manifest(manifest_writer *mwriter,
 								 const char *manifest_path,
-								 size_t size, time_t mtime,
+								 uint64 size, time_t mtime,
 								 pg_checksum_type checksum_type,
 								 int checksum_length,
 								 uint8 *checksum_payload);
diff --git a/src/bin/pg_verifybackup/astreamer_verify.c b/src/bin/pg_verifybackup/astreamer_verify.c
index f7ecdc1f655..a442b2849fc 100644
--- a/src/bin/pg_verifybackup/astreamer_verify.c
+++ b/src/bin/pg_verifybackup/astreamer_verify.c
@@ -207,9 +207,11 @@ member_verify_header(astreamer *streamer, astreamer_member *member)
 	if (m->size != member->size)
 	{
 		report_backup_error(mystreamer->context,
-							"\"%s\" has size %lld in \"%s\" but size %zu in the manifest",
-							member->pathname, (long long int) member->size,
-							mystreamer->archive_name, m->size);
+							"\"%s\" has size %llu in \"%s\" but size %llu in the manifest",
+							member->pathname,
+							(unsigned long long) member->size,
+							mystreamer->archive_name,
+							(unsigned long long) m->size);
 		m->bad = true;
 		return;
 	}
@@ -294,9 +296,10 @@ member_verify_checksum(astreamer *streamer)
 	if (mystreamer->checksum_bytes != m->size)
 	{
 		report_backup_error(mystreamer->context,
-							"file \"%s\" in \"%s\" should contain %zu bytes, but read %zu bytes",
+							"file \"%s\" in \"%s\" should contain %llu bytes, but read %llu bytes",
 							m->pathname, mystreamer->archive_name,
-							m->size, mystreamer->checksum_bytes);
+							(unsigned long long) m->size,
+							(unsigned long long) mystreamer->checksum_bytes);
 		return;
 	}
 
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index 32467a1ba09..0719cb89783 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -61,7 +61,7 @@ static void verifybackup_version_cb(JsonManifestParseContext *context,
 static void verifybackup_system_identifier(JsonManifestParseContext *context,
 										   uint64 manifest_system_identifier);
 static void verifybackup_per_file_cb(JsonManifestParseContext *context,
-									 const char *pathname, size_t size,
+									 const char *pathname, uint64 size,
 									 pg_checksum_type checksum_type,
 									 int checksum_length,
 									 uint8 *checksum_payload);
@@ -547,7 +547,7 @@ verifybackup_system_identifier(JsonManifestParseContext *context,
  */
 static void
 verifybackup_per_file_cb(JsonManifestParseContext *context,
-						 const char *pathname, size_t size,
+						 const char *pathname, uint64 size,
 						 pg_checksum_type checksum_type,
 						 int checksum_length, uint8 *checksum_payload)
 {
@@ -719,8 +719,9 @@ verify_plain_backup_file(verifier_context *context, char *relpath,
 	if (m->size != sb.st_size)
 	{
 		report_backup_error(context,
-							"\"%s\" has size %lld on disk but size %zu in the manifest",
-							relpath, (long long int) sb.st_size, m->size);
+							"\"%s\" has size %llu on disk but size %llu in the manifest",
+							relpath, (unsigned long long) sb.st_size,
+							(unsigned long long) m->size);
 		m->bad = true;
 	}
 
@@ -1101,7 +1102,7 @@ verify_file_checksum(verifier_context *context, manifest_file *m,
 	const char *relpath = m->pathname;
 	int			fd;
 	int			rc;
-	size_t		bytes_read = 0;
+	uint64		bytes_read = 0;
 	uint8		checksumbuf[PG_CHECKSUM_MAX_LENGTH];
 	int			checksumlen;
 
@@ -1164,8 +1165,9 @@ verify_file_checksum(verifier_context *context, manifest_file *m,
 	if (bytes_read != m->size)
 	{
 		report_backup_error(context,
-							"file \"%s\" should contain %zu bytes, but read %zu bytes",
-							relpath, m->size, bytes_read);
+							"file \"%s\" should contain %llu bytes, but read %llu bytes",
+							relpath, (unsigned long long) m->size,
+							(unsigned long long) bytes_read);
 		return;
 	}
 
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.h b/src/bin/pg_verifybackup/pg_verifybackup.h
index 183b1d5111b..2f864fb0f3f 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.h
+++ b/src/bin/pg_verifybackup/pg_verifybackup.h
@@ -29,7 +29,7 @@ typedef struct manifest_file
 {
 	uint32		status;			/* hash status */
 	const char *pathname;
-	size_t		size;
+	uint64		size;
 	pg_checksum_type checksum_type;
 	int			checksum_length;
 	uint8	   *checksum_payload;
diff --git a/src/common/parse_manifest.c b/src/common/parse_manifest.c
index 5a7b491e9a9..ad2d0fd808f 100644
--- a/src/common/parse_manifest.c
+++ b/src/common/parse_manifest.c
@@ -650,7 +650,7 @@ static void
 json_manifest_finalize_file(JsonManifestParseState *parse)
 {
 	JsonManifestParseContext *context = parse->context;
-	size_t		size;
+	uint64		size;
 	char	   *ep;
 	int			checksum_string_length;
 	pg_checksum_type checksum_type;
@@ -688,7 +688,7 @@ json_manifest_finalize_file(JsonManifestParseState *parse)
 	}
 
 	/* Parse size. */
-	size = strtoul(parse->size, &ep, 10);
+	size = strtou64(parse->size, &ep, 10);
 	if (*ep)
 		json_manifest_parse_failure(parse->context,
 									"file size is not an integer");
diff --git a/src/include/common/parse_manifest.h b/src/include/common/parse_manifest.h
index ee571a568a1..1b8bc447e44 100644
--- a/src/include/common/parse_manifest.h
+++ b/src/include/common/parse_manifest.h
@@ -28,7 +28,7 @@ typedef void (*json_manifest_system_identifier_callback) (JsonManifestParseConte
 														  uint64 manifest_system_identifier);
 typedef void (*json_manifest_per_file_callback) (JsonManifestParseContext *,
 												 const char *pathname,
-												 size_t size, pg_checksum_type checksum_type,
+												 uint64 size, pg_checksum_type checksum_type,
 												 int checksum_length, uint8 *checksum_payload);
 typedef void (*json_manifest_per_wal_range_callback) (JsonManifestParseContext *,
 													  TimeLineID tli,
-- 
2.39.3 (Apple Git-145)