pgreadfile
Read and overwrite server-local files as bytea through C functions
pgreadfile · Read and overwrite server-local files as bytea through C functions
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100353 | pgreadfile | pgreadfile | 1.0 | UTIL | Unknown | C |
PostgreSQL · 11
Usage
Sources:
pgreadfile 1.0 exposes unrestricted server-side file reading and writing through pgreadfile(text) and pgwritefile(text, bytea). The published extension is unsafe for a multi-user or production database.
Revoke access during installation
Do not grant the write function to application roles. If a reviewed administrative workflow must read a fixed approved file, grant only the read function to a tightly controlled role and validate the path outside this function.
Caveats
- The install SQL leaves both functions executable by public. Any database user can otherwise read every server file visible to the PostgreSQL operating-system account and overwrite or truncate every writable file.
- Both functions are falsely declared immutable even though they depend on and mutate external state. Planner constant folding or expression reuse can execute them at surprising times; the write declaration is especially hazardous.
- The read function loads the entire file into backend memory without a size limit. A large file can exhaust memory.
- File-open failures and some write failures are not reported reliably; short writes are ignored. Symbolic links and path races are not controlled.
- Upstream documents compilation only against PostgreSQL 11 and provides no tests, permission model, or current compatibility evidence. Prefer maintained core facilities with predefined roles and explicit path controls.