Skip to content

file_fdw: PROGRAM foreign tables are accepted but SELECT panics #76

Description

@AtPaL

Summary

file_fdw currently accepts the foreign-table program option, but scanning such a table reaches a Rust panic! instead of either executing COPY FROM PROGRAM or returning a controlled SQL error.

Why this looks reachable

The validator path accepts program for foreign tables:

  • crates/contrib/file_fdw/src/lib.rs:207 treats "filename" | "program" as valid table-level source options.
  • crates/contrib/file_fdw/src/lib.rs:218 checks pg_execute_server_program privilege for program, but does not reject it as unsupported.
  • file_get_options() then preserves the is_program flag for executor setup.
  • crates/contrib/file_fdw/src/lib.rs:632 file_begin_foreign_scan() calls file_get_options(), and the is_program branch panics at line 646:
panic!(
    "file_fdw: program option (COPY FROM PROGRAM, OpenPipeStream lane) is unported \
     for table \"{}\"",
    rel.name()
);

I also checked origin/v0.3-beta; it still has the same file_begin_foreign_scan() panic path.

Reproduction sketch

As a role that can set program on file_fdw foreign tables:

CREATE EXTENSION file_fdw;
CREATE SERVER file_srv FOREIGN DATA WRAPPER file_fdw;

-- Superuser, or a role with pg_execute_server_program, can create this option.
CREATE FOREIGN TABLE ft_program(line text)
  SERVER file_srv
  OPTIONS (program 'printf "hello\n"', format 'text');

SELECT * FROM ft_program;

Expected behavior

Either:

  • support COPY FROM PROGRAM for file_fdw scans, matching PostgreSQL behavior, or
  • reject the unsupported program path with a normal SQL error, preferably at validation time or at scan startup.

The important part is that reachable SQL should not be able to panic the backend.

Actual behavior

The option is accepted, then SELECT reaches file_begin_foreign_scan() and panics because the OpenPipeStream lane is marked unported.

Validation performed

  • Refreshed the current issue list and searched for existing file_fdw / COPY FROM PROGRAM / program option / OpenPipeStream reports; I did not find a duplicate.
  • Checked origin/v0.3-beta; the same panic branch is still present there.
  • Ran cargo test -p file_fdw --lib; the crate builds and its current 2 unit tests pass.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions