Re: pg_stat_get_activity(): integer overflow due to (int) * (int) for MemoryContextAllocHuge()
Jakub Wartak <jakub.wartak@enterprisedb.com>
From: Jakub Wartak <jakub.wartak@enterprisedb.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Andres Freund <andres@anarazel.de>,
Peter Eisentraut <peter@eisentraut.org>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>,
Robert Haas <robertmhaas@gmail.com>
Date: 2023-09-28T09:01:14Z
Lists: pgsql-hackers
Attachments
- v3-0001-Introduce-memory-limit-for-BackendActivityBuffer-.patch (application/octet-stream) patch v3-0001
On Thu, Sep 28, 2023 at 12:53 AM Michael Paquier <michael@paquier.xyz> wrote: > > On Wed, Sep 27, 2023 at 10:29:25AM -0700, Andres Freund wrote: > > I don't think going for size_t is a viable path for fixing this. I'm pretty > > sure the initial patch would trigger a type mismatch from guc_tables.c - we > > don't have infrastructure for size_t GUCs. > > Nothing marked as PGDLLIMPORT uses size_t in the tree currently, FWIW. > > > Perhaps we ought to error out (in BackendStatusShmemSize() or such) if > > pgstat_track_activity_query_size * MaxBackends >= 4GB? > > Yeah, agreed that putting a check like that could catch errors more > quickly. Hi, v3 attached. I had a problem coming out with a better error message, so suggestions are welcome. The cast still needs to be present as per above suggestion as 3GB is still valid buf size and still was causing integer overflow. We just throw an error on >= 4GB with v3. -J.
Commits
-
Avoid memory size overflow when allocating backend activity buffer
- 9b3900cdb734 12.17 landed
- a0b013625908 13.13 landed
- f91c87b31463 14.10 landed
- 95e91da66cf5 15.5 landed
- 75f31a3f2674 16.1 landed
- a956bd3fa9d9 17.0 landed