Read until EOF vice stat-reported size in read_binary_file
authorJoe Conway <mail@joeconway.com>
Sat, 4 Jul 2020 10:28:21 +0000 (06:28 -0400)
committerJoe Conway <mail@joeconway.com>
Sat, 4 Jul 2020 10:28:21 +0000 (06:28 -0400)
commit0025c3a2c295459002711e0b37e48e3b067a83ba
tree6869d4c1ec8f2517c8f5cac4dc6642e55ee60910
parent9233624b128b41fd410712a7223821878f1943b0
Read until EOF vice stat-reported size in read_binary_file

read_binary_file(), used by SQL functions pg_read_file() and friends,
uses stat to determine file length to read, when not passed an explicit
length as an argument. This is problematic, for example, if the file
being read is a virtual file with a stat-reported length of zero.
Arrange to read until EOF, or StringInfo data string lenth limit, is
reached instead.

Original complaint and patch by me, with significant review, corrections,
advice, and code optimizations by Tom Lane. Backpatched to v11. Prior to
that only paths relative to the data and log dirs were allowed for files,
so no "zero length" files were reachable anyway.

Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/flat/969b8d82-5bb2-5fa8-4eb1-f0e685c5d736%40joeconway.com
Backpatch-through: 11
contrib/adminpack/expected/adminpack.out
src/backend/utils/adt/genfile.c