pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: d.koval@postgrespro.ru
Subject: BUG #17288: PSQL bug with COPY command (Windows)
Date: Wed, 17 Nov 2021 10:02:08 +0000
Message-ID: <17288-6b58a91025a8a8a3@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      17288
Logged by:          Dmitry Koval
Email address:      d.koval@postgrespro.ru
PostgreSQL version: 14.1
Operating system:   Windows 10 (21H1)
Description:        

Hi,
there is a problem on the REL_14_STABLE branch (on the REL_14_1
branch too). When executing a query under Windows 10 (21H1)

\copy (SELECT 1) TO stdout

PSQL utility prints error 
"could not stat file" (null) ": Invalid argument" and crashes.
There is no error under Ubuntu 20.04 LTS.

Issue source: commit bed90759fcbcd72d4d06969eebab81e47326f9a 
("Fix our Windows stat() emulation to handle file sizes > 4GB.", 
discussion: https://postgr.es/m/15858-9572469fd3b73263@postgresql.org).

In this commit function stat () was replaced to function 
GetFileInformationByHandle() 
(see src/port/win32stat.c, function fileinfo_to_stat()):

	if (!GetFileInformationByHandle(hFile, &fiData))
	{
		_dosmaperr(GetLastError());
		return -1;
	}

Function GetFileInformationByHandle() works for files but can not work
with streams like "stdout".
For "stdout" the GetFileInformationByHandle () function returns an error
(GetLastError () == ERROR_INVALID_FUNCTION), which causes PSQL crash.

Examples of errors processing for function GetFileInformationByHandle()
in other applications:

1) https://github.com/python/cpython/blob/main/Modules/posixmodule.c
2)
https://doxygen.reactos.org/da/d6a/subsystems_2mvdm_2ntvdm_2hardware_2disk_8c_source.html

Quick fix in src/port/win32stat.c: 
in case function GetFileInformationByHandle() returns a specific error
code, call the _stat64() function for this descriptor.
It's not elegant, but it works.

(I'll attach file with patch in next email).

With best regards,
Dmitry Koval.



view thread (29+ messages)  latest in thread

Message-ID: <17288-6b58a91025a8a8a3@postgresql.org>
Permalink:  ../17288-6b58a91025a8a8a3@postgresql.org/
Also on:    postgresql.org/message-id/17288-6b58a91025a8a8a3@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, d.koval@postgrespro.ru
  Subject: Re: BUG #17288: PSQL bug with COPY command (Windows)
  In-Reply-To: <17288-6b58a91025a8a8a3@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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