Use the correct sizeof() in BufFileLoadBuffer
authorTomas Vondra <tomas.vondra@postgresql.org>
Fri, 24 Jan 2025 23:36:48 +0000 (00:36 +0100)
committerTomas Vondra <tomas.vondra@postgresql.org>
Sat, 25 Jan 2025 01:12:59 +0000 (02:12 +0100)
The sizeof() call should reference buffer.data, because that's the
buffer we're reading data into, not the whole PGAlignedBuffer union.
This was introduced by 44cac93464, which replaced the simple buffer
with a PGAlignedBuffer field.

It's benign, because the buffer is the largest field of the union, so
the sizes are the same. But it's easy to trip over this in a patch, so
fix and backpatch. Commit 44cac93464 went into 12, but that's EOL.

Backpatch-through: 13
Discussion: https://postgr.es/m/928bdab1-6567-449f-98c4-339cd2203b87@vondra.me

src/backend/storage/file/buffile.c

index 6449f82a72bdc283f145864b7c85392641f5cf5f..a4541b87b8fd3a35230a4a5e5ab648612c6e60ac 100644 (file)
@@ -459,7 +459,7 @@ BufFileLoadBuffer(BufFile *file)
     */
    file->nbytes = FileRead(thisfile,
                            file->buffer.data,
-                           sizeof(file->buffer),
+                           sizeof(file->buffer.data),
                            file->curOffset,
                            WAIT_EVENT_BUFFILE_READ);
    if (file->nbytes < 0)