]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Add assertion about ssize_t narrowing in AIO code
authorPeter Eisentraut <peter@eisentraut.org>
Wed, 15 Jul 2026 08:58:13 +0000 (10:58 +0200)
committerPeter Eisentraut <peter@eisentraut.org>
Wed, 15 Jul 2026 09:00:39 +0000 (11:00 +0200)
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 <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/f9aab072-0078-49e4-ab93-3b08086a4406@eisentraut.org

src/backend/storage/aio/aio_io.c

index 72b4c9feb3a69750098bf0175596a0536d02692b..132868130e7cde86a6d20dc9f25802fabc99b920 100644 (file)
@@ -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);