Re: [BUG] hstore integer overflow when constructing large values

From: Tender Wang <tndrwang(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Keyerror Smart <smartkeyerror(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [BUG] hstore integer overflow when constructing large values
Date: 2026-08-17 03:06:17
Message-ID: CAHewXNkNYnxYYhukSOo6OFeoP15jeTgbX2n+VYXSZ0eZh1HspQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Michael Paquier <michael(at)paquier(dot)xyz> 于2026年8月17日周一 10:42写道:

> While looking at that, I am reaching similar conclusions in terms of
> CALCDATASIZE(), and your version feels weird by having both a static
> inline function *and* a macro.. Your previous hstoreAddPairLen() is
> also tempting to keep. We apply the same rule in three places based
> on if a pair is null or not.

Agree

> Attached is presumably what I would do, which has some similarities
> with your v2, but it's a bit more expanded.

Thanks for the patch. I went through v3, and I think it is better and more
complete than my v2.

There is just one thing I noticed in `hstore_subscript_assign()`:

```
vsize = hstoreCalcDataSize(s1count + 1,
VARSIZE(hs) + p.keylen + p.vallen);
```

Here `VARSIZE(hs) + p.keylen + p.vallen` is still calculated using
unchecked additions before being passed to `hstoreCalcDataSize()`.

Given that the rest of the patch is moving allocation-size arithmetic to
`Size` and `add_size()`/`mul_size()`, I wonder if this should use
`add_size()` as well.

Perhaps the existing size limits make an overflow there unreachable in
practice, but using `add_size()` would seem more consistent with the rest
of this patch.

Other than that, v3 looks good to me.

--
Thanks,
Tender Wang

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2026-08-17 03:07:46 Re: basebackup: do not verify checksums on pages written before enabling checksums
Previous Message Bharath Rupireddy 2026-08-17 03:00:00 Re: Multi-insert for logical replication apply