From: Peter Eisentraut Date: Tue, 7 Jul 2026 09:45:09 +0000 (+0200) Subject: Don't cast pgoff_t to possibly 32-bit types for output X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=04fc2564fbbabe97cadbf782e8d40b8e3f7b22a5;p=thirdparty%2Fpostgresql.git Don't cast pgoff_t to possibly 32-bit types for output pgoff_t is most likely a 64-bit integer, so casting it to a 32-bit type for output could lose data. In the cases addressed here, the files cannot actually get that large, so this is only cosmetic and to set better examples for the future. (Similar issues that could have actual practical impact were addressed separately in commit e8f851d6172.) In one case, the 32-bit size is baked into the protocol, so here we add an elog and document this discrepancy. Reviewed-by: Heikki Linnakangas Reviewed-by: Chao Li Discussion: https://www.postgresql.org/message-id/flat/20ce62fa-47fc-457b-b504-12f3c1651726%40eisentraut.org --- diff --git a/src/backend/access/heap/rewriteheap.c b/src/backend/access/heap/rewriteheap.c index 5a5398a76ae..0ccd392c3dc 100644 --- a/src/backend/access/heap/rewriteheap.c +++ b/src/backend/access/heap/rewriteheap.c @@ -1104,8 +1104,8 @@ heap_xlog_logical_rewrite(XLogReaderState *r) if (ftruncate(fd, xlrec->offset) != 0) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not truncate file \"%s\" to %u: %m", - path, (uint32) xlrec->offset))); + errmsg("could not truncate file \"%s\" to %lld: %m", + path, (long long int) xlrec->offset))); pgstat_report_wait_end(); data = XLogRecGetData(r) + sizeof(*xlrec); diff --git a/src/backend/backup/walsummary.c b/src/backend/backup/walsummary.c index 0cdc86af30b..48b7bd8c521 100644 --- a/src/backend/backup/walsummary.c +++ b/src/backend/backup/walsummary.c @@ -306,9 +306,9 @@ WriteWalSummary(void *wal_summary_io, void *data, int length) if (nbytes != length) ereport(ERROR, (errcode_for_file_access(), - errmsg("could not write file \"%s\": wrote only %d of %d bytes at offset %u", + errmsg("could not write file \"%s\": wrote only %d of %d bytes at offset %lld", FilePathName(io->file), nbytes, - length, (unsigned) io->filepos), + length, (long long) io->filepos), errhint("Check free disk space."))); io->filepos += nbytes; diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index c931d9b4fa8..ae9ffd0d096 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -661,6 +661,12 @@ SendTimeLineHistory(TimeLineHistoryCmd *cmd) (errcode_for_file_access(), errmsg("could not seek to beginning of file \"%s\": %m", path))); + /* + * unlikely in practice, but to document the implicit integer conversion + */ + if (histfilelen > UINT32_MAX) + elog(ERROR, "timeline history file is too large"); + pq_sendint32(&buf, histfilelen); /* col2 len */ bytesleft = histfilelen; diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index 4cf4717f764..b8a66b3b475 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -1521,8 +1521,8 @@ ReportTemporaryFileUsage(const char *path, pgoff_t size) { if ((size / 1024) >= log_temp_files) ereport(LOG, - (errmsg("temporary file: path \"%s\", size %lu", - path, (unsigned long) size))); + (errmsg("temporary file: path \"%s\", size %lld", + path, (long long) size))); } } diff --git a/src/bin/pg_upgrade/slru_io.c b/src/bin/pg_upgrade/slru_io.c index 2188a287850..aa9d59a0d7b 100644 --- a/src/bin/pg_upgrade/slru_io.c +++ b/src/bin/pg_upgrade/slru_io.c @@ -133,8 +133,8 @@ SlruReadSwitchPageSlow(SlruSegState *state, uint64 pageno) if (rc == 0) { /* unexpected EOF */ - pg_log(PG_WARNING, "unexpected EOF reading file \"%s\" at offset %u, reading as zeros", - state->fn, (unsigned int) offset); + pg_log(PG_WARNING, "unexpected EOF reading file \"%s\" at offset %lld, reading as zeros", + state->fn, (long long int) offset); memset(&state->buf.data[bytes_read], 0, BLCKSZ - bytes_read); break; }