sendFileWithContent() does not advance the source pointer

Antonin Houska <ah@cybertec.at>

From: Antonin Houska <ah@cybertec.at>
To: pgsql-hackers@postgresql.org
Date: 2022-12-08T19:44:05Z
Lists: pgsql-hackers

Attachments

When checking something else in the base backup code, I've noticed that
sendFileWithContent() does not advance the 'content' pointer. The sink buffer
is large enough (32kB) so that the first iteration usually processes the whole
file (only special files are processed by this function), and thus that the
problem is hidden.

However it's possible to hit the issue: if there are too many tablespaces,
pg_basebackup generates corrupted tablespace_map. Instead of writing all the
tablespace paths it writes only some and then starts to write the contents
from the beginning again.

The attached script generates scripts to create many tablespaces as well as
the underlying directories. Fix is attached here as well.

-- 
Antonin Houska
Web: https://www.cybertec-postgresql.com

Commits

  1. Fix failure to advance content pointer in sendFileWithContent.