From cba8024ab07162e4474501fe9523db478ea1aa0c Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 29 Jun 2026 13:37:54 +0200 Subject: [PATCH v1 15/15] 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. --- src/backend/storage/aio/aio_io.c | 5 +++++ 1 file changed, 5 insertions(+) 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); -- 2.54.0