pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix detection of unseekable files for fseek() and ftello() with
3+ messages / 1 participants
[nested] [flat]

* pgsql: Fix detection of unseekable files for fseek() and ftello() with
@ 2023-04-12 00:10  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 3+ messages in thread

From: Michael Paquier @ 2023-04-12 00:10 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix detection of unseekable files for fseek() and ftello() with MSVC

Calling fseek() or ftello() on a handle to a non-seeking device such as
a pipe or a communications device is not supported.  Unfortunately,
MSVC's flavor of these routines, _fseeki64() and _ftelli64(), do not
return an error when given a pipe as handle.  Some of the logic of
pg_dump and restore relies on these routines to check if a handle is
seekable, causing failures when passing the contents of pg_dump to
pg_restore through a pipe, for example.

This commit introduces wrappers for fseeko() and ftello() on MSVC so as
any callers are able to properly detect the cases of non-seekable
handles.  This relies mainly on GetFileType(), sharing a bit of code
with the MSVC port for fstat().  The code in charge of getting a file
type is refactored into a new file called win32common.c, shared by
win32stat.c and the new win32fseek.c.  It includes the MSVC ports for
fseeko() and ftello().

Like 765f5df, this is backpatched down to 14, where the fstat()
implementation for MSVC is able to understand about files larger than
4GB in size.  Using a TAP test for that is proving to be tricky as
IPC::Run handles the pipes by itself, still I have been able to check
the fix manually.

Reported-by: Daniel Watzinger
Author: Juan José Santamaría Flecha, Michael Paquier
Discussion: https://postgr.es/m/CAC+AXB26a4EmxM2suXxPpJaGrqAdxracd7hskLg-zxtPB50h7A@mail.gmail.com
Backpatch-through: 14

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a923e21631a29dc8b8781d7d02b5003d0df64ca3

Modified Files
--------------
configure                     |  6 ++++
configure.ac                  |  1 +
src/include/port/win32_port.h | 12 +++++--
src/port/meson.build          |  2 ++
src/port/win32common.c        | 68 +++++++++++++++++++++++++++++++++++++++
src/port/win32fseek.c         | 75 +++++++++++++++++++++++++++++++++++++++++++
src/port/win32stat.c          | 22 ++-----------
src/tools/msvc/Mkvcbuild.pm   |  2 ++
8 files changed, 166 insertions(+), 22 deletions(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Fix detection of unseekable files for fseek() and ftello() with
@ 2023-04-12 00:10  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 3+ messages in thread

From: Michael Paquier @ 2023-04-12 00:10 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix detection of unseekable files for fseek() and ftello() with MSVC

Calling fseek() or ftello() on a handle to a non-seeking device such as
a pipe or a communications device is not supported.  Unfortunately,
MSVC's flavor of these routines, _fseeki64() and _ftelli64(), do not
return an error when given a pipe as handle.  Some of the logic of
pg_dump and restore relies on these routines to check if a handle is
seekable, causing failures when passing the contents of pg_dump to
pg_restore through a pipe, for example.

This commit introduces wrappers for fseeko() and ftello() on MSVC so as
any callers are able to properly detect the cases of non-seekable
handles.  This relies mainly on GetFileType(), sharing a bit of code
with the MSVC port for fstat().  The code in charge of getting a file
type is refactored into a new file called win32common.c, shared by
win32stat.c and the new win32fseek.c.  It includes the MSVC ports for
fseeko() and ftello().

Like 765f5df, this is backpatched down to 14, where the fstat()
implementation for MSVC is able to understand about files larger than
4GB in size.  Using a TAP test for that is proving to be tricky as
IPC::Run handles the pipes by itself, still I have been able to check
the fix manually.

Reported-by: Daniel Watzinger
Author: Juan José Santamaría Flecha, Michael Paquier
Discussion: https://postgr.es/m/CAC+AXB26a4EmxM2suXxPpJaGrqAdxracd7hskLg-zxtPB50h7A@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_14_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/34105eea62e1a607a30596840c7e6dd1cd3feb14

Modified Files
--------------
configure                     |  6 ++++
configure.ac                  |  1 +
src/include/port/win32_port.h | 12 +++++--
src/port/win32common.c        | 68 +++++++++++++++++++++++++++++++++++++++
src/port/win32fseek.c         | 75 +++++++++++++++++++++++++++++++++++++++++++
src/port/win32stat.c          | 22 ++-----------
src/tools/msvc/Mkvcbuild.pm   |  3 +-
7 files changed, 164 insertions(+), 23 deletions(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* pgsql: Fix detection of unseekable files for fseek() and ftello() with
@ 2023-04-12 00:10  Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 3+ messages in thread

From: Michael Paquier @ 2023-04-12 00:10 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix detection of unseekable files for fseek() and ftello() with MSVC

Calling fseek() or ftello() on a handle to a non-seeking device such as
a pipe or a communications device is not supported.  Unfortunately,
MSVC's flavor of these routines, _fseeki64() and _ftelli64(), do not
return an error when given a pipe as handle.  Some of the logic of
pg_dump and restore relies on these routines to check if a handle is
seekable, causing failures when passing the contents of pg_dump to
pg_restore through a pipe, for example.

This commit introduces wrappers for fseeko() and ftello() on MSVC so as
any callers are able to properly detect the cases of non-seekable
handles.  This relies mainly on GetFileType(), sharing a bit of code
with the MSVC port for fstat().  The code in charge of getting a file
type is refactored into a new file called win32common.c, shared by
win32stat.c and the new win32fseek.c.  It includes the MSVC ports for
fseeko() and ftello().

Like 765f5df, this is backpatched down to 14, where the fstat()
implementation for MSVC is able to understand about files larger than
4GB in size.  Using a TAP test for that is proving to be tricky as
IPC::Run handles the pipes by itself, still I have been able to check
the fix manually.

Reported-by: Daniel Watzinger
Author: Juan José Santamaría Flecha, Michael Paquier
Discussion: https://postgr.es/m/CAC+AXB26a4EmxM2suXxPpJaGrqAdxracd7hskLg-zxtPB50h7A@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/5c32549460fcabfb34ce47f96499bf753aaabeea

Modified Files
--------------
configure                     |  6 ++++
configure.ac                  |  1 +
src/include/port/win32_port.h | 12 +++++--
src/port/win32common.c        | 68 +++++++++++++++++++++++++++++++++++++++
src/port/win32fseek.c         | 75 +++++++++++++++++++++++++++++++++++++++++++
src/port/win32stat.c          | 22 ++-----------
src/tools/msvc/Mkvcbuild.pm   |  2 +-
7 files changed, 163 insertions(+), 23 deletions(-)



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2023-04-12 00:10 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-04-12 00:10 pgsql: Fix detection of unseekable files for fseek() and ftello() with Michael Paquier <michael@paquier.xyz>
2023-04-12 00:10 pgsql: Fix detection of unseekable files for fseek() and ftello() with Michael Paquier <michael@paquier.xyz>
2023-04-12 00:10 pgsql: Fix detection of unseekable files for fseek() and ftello() with Michael Paquier <michael@paquier.xyz>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox