Re: postgres_fdw can crash on malformed remote results

From: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Etsuro Fujita <etsuro(dot)fujita(at)gmail(dot)com>
Subject: Re: postgres_fdw can crash on malformed remote results
Date: 2026-12-02 09:47:29
Message-ID: CAJTYsWXn05O7SwCBTmsv7cqH1R5iCFS7-khVjxn+hS76ZgFpXw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Wed, 2 Dec 2026 at 08:59, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>
> On Wed, Dec 2, 2026 at 4:10 AM Corey Huinker <corey(dot)huinker(at)gmail(dot)com> wrote:
> > It's a trivial and lightweight fix, with cited precedent for making the same change, applies clean and passes tests.
>
> +1
>
> + if (PQntuples(res) < 1 || PQnfields(res) < 1)
> + elog(ERROR, "unexpected result from remote EXPLAIN command");
>
> Since EXPLAIN always returns one column, isn't it better to use
> "PQnfields(res) != 1", consistent with the "PQnfields(res) != 8" check
> for IMPORT FOREIGN SCHEMA?

Ahh makes sense, done that way in v2.

For Corey:

The fake server I used was put together by hand, but the attached
Python script (generated with Codex) roughly simulates it, in case it's
useful.

Regards,
Ayush

Attachment Content-Type Size
v2-0001-postgres_fdw-Validate-remote-query-result-shapes.patch application/octet-stream 2.0 KB
fake_pg_server.py text/x-python 5.4 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2026-12-02 09:51:21 Re: Preserve conflict log table during upgrade
Previous Message Álvaro Herrera 2026-12-02 09:42:20 Re: REPACK (CONCURRENTLY) fails during parallel build of exclusion constraint indexes