Re: [BUG + PATCH] DSA pagemap out-of-bounds in make_new_segment odd-sized path

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Sami Imseih <samimseih(at)gmail(dot)com>, paul(dot)bunn(at)icloud(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [BUG + PATCH] DSA pagemap out-of-bounds in make_new_segment odd-sized path
Date: 2026-03-06 00:54:35
Message-ID: BE7DBB95-BD78-446E-8026-68E9140B348B@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Mar 6, 2026, at 06:49, Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> On Thu, Mar 05, 2026 at 04:25:57PM -0600, Sami Imseih wrote:
>> With the above assert in place, the usable_pages of 879 ars you have
>> in test_dsa.c crashes
>> due to the assertion failure.
>
> Yep, the assertion looks useful to have in place.
>

While debugging the code, I used the same Assert, which helped quickly trigger the bug. Without the Assert, even if an OOB happens, it might not immediately crash.

But now that the bug has been identified and fixed, and the function is self-contained, I’m not sure how much the Assert would still help. Unless we are not sure whether the fix really works, otherwise I don’t think the Assert is necessary.

However, this is not a strong objection. If we do want to add the Assert, I notice the expression MAXALIGN(sizeof(dsa_segment_header)) + MAXALIGN(sizeof(FreePageManager)) appears multiple times, and the Assert actually uses it as well. We could add a local variable like:
```
size_t metadata_fixed_bytes =
MAXALIGN(sizeof(dsa_segment_header)) +
MAXALIGN(sizeof(FreePageManager));
```

That would help reduce code redundancy.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jacob Champion 2026-03-06 00:57:13 Re: [oauth] Stabilize the libpq-oauth ABI (and allow alternative implementations?)
Previous Message Andres Freund 2026-03-06 00:43:51 Re: Why clearing the VM doesn't require registering vm buffer in wal record