From: Peter Eisentraut Date: Wed, 15 Jul 2026 08:58:13 +0000 (+0200) Subject: Add assertion about ssize_t narrowing in AIO code X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01f78a84bf5aca4c00fe1168381830aca6f1b873;p=thirdparty%2Fpostgresql.git Add assertion about ssize_t narrowing in AIO code The result from pg_preadv() or pg_pwritev(), which is of type ssize_t, is assigned to PgAioHandle.result, which is of type int. This should be ok because the maximum result is limited by PG_IOV_MAX times BLCKSZ. Add an assertion and a code comment to explain and check this. Reviewed-by: Heikki Linnakangas Discussion: https://www.postgresql.org/message-id/flat/f9aab072-0078-49e4-ab93-3b08086a4406@eisentraut.org --- diff --git a/src/backend/storage/aio/aio_io.c b/src/backend/storage/aio/aio_io.c index 72b4c9feb3a..132868130e7 100644 --- a/src/backend/storage/aio/aio_io.c +++ b/src/backend/storage/aio/aio_io.c @@ -141,6 +141,11 @@ pgaio_io_perform_synchronously(PgAioHandle *ioh) elog(ERROR, "trying to execute invalid IO operation"); } + /* + * ssize_t to int conversion should be ok because result should be no more + * than PG_IOV_MAX times BLCKSZ. + */ + Assert(result <= INT_MAX); ioh->result = result < 0 ? -errno : result; pgaio_io_process_completion(ioh, ioh->result);