Re: BUG #17254: Crash with 0xC0000409 in pg_stat_statements when pg_stat_tmp\pgss_query_texts.stat exceeded 2GB.

Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>

From: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
To: egashira.yusuke@fujitsu.com, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Date: 2021-10-29T19:43:35Z
Lists: pgsql-bugs
Thanks for the report.

On Fri, Oct 29, 2021 at 12:52 PM PG Bug reporting form <
noreply@postgresql.org> wrote:

>
> The MSDN documentation says that the upper limit of the _read() argument is
> INT_MAX (about 2GB), but the size gotten by fstat() exceeds this limit, so
> I
> think we encountered server crash by an exception error.
>
>
> https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/read?view=msvc-160
> > If buffer is NULL, or if buffer_size > INT_MAX, the invalid parameter
> handler is invoked.
>
> Until PostgreSQL 13, fstat() failed and returned ERROR when a file was
> larger than 2GB, but as a result of improvements to fstat() in PostgreSQL
> 14, it appears that _read() has exceeded its limit and now causes a crash.
>
> The value of MaxAllocHugeSize is being oversized when _WIN64 is defined
[1]. Shouldn't the limit for a slurp be MaxAllocSize?

[1]
https://docs.microsoft.com/en-us/cpp/c-runtime-library/data-type-constants?view=msvc-160

Regards,

Juan José Santamaría Flecha

Commits

  1. Don't try to read a multi-GB pg_stat_statements file in one call.