Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcJCo-00053A-9l for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Mar 2023 04:57:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pcJCm-0006Wv-EF for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Mar 2023 04:57:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcJCm-0006Wm-4O for pgsql-hackers@lists.postgresql.org; Wed, 15 Mar 2023 04:57:40 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcJCj-00058z-J5 for pgsql-hackers@postgresql.org; Wed, 15 Mar 2023 04:57:39 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id D30CD3200AB1; Wed, 15 Mar 2023 00:57:34 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 15 Mar 2023 00:57:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1678856254; x=1678942654; bh=Hj Hl18HN7qjIx0jxUsdTMs1Veo7hEIDpQT25uqeEF24=; b=g1eeb8zdFvY4UXRoCh QG8zU3vu3L+JpCe4nkkHEd3IpYjU53oGQegC7tGdrqZBAWPUvcFtjxR1BSzgCmpK SitZkcADzd7nvm+tjzacDCVziMHwAoYpIPyUhWPdksLkssl0Le7zG22sfOhpBT8D x3YB6UBTgmwDlph5pnByQwfgMJ1AfVgimkPCbNH6CF+UJi3PLseeSuAsHTwZou99 09+FNbYThon9J4PqFnVjtWRGr1k6MnQXVFBxLk+lYHIvjlZqkk638fPGU9jGSMCf uBrAyzfJQXWaGa+Ibb+x1CUcZ6Y+hFPdyoTFY1D6CQSvYKhqUsdqd9pY8E0P3abQ gqbw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1678856254; x=1678942654; bh=HjHl18HN7qjIx 0jxUsdTMs1Veo7hEIDpQT25uqeEF24=; b=eER+Um4loRiRA5RX9+rh1jvOAcMvQ w2DIBXEMKK29rmnCTK4O7r9ujV13370msTq8DkcG2JYO2KVSItWrF7JGiaGDS3QB bSYuqLONeUCwkO5Kr+pMy3VsJETyM6C9H0ewK0mv2JACLiLcB0md2Zwo3t1KnpNo s3TF/DlQLXmWpiGZlK6Nm/yfQtZoo8L5/wfFRGb2Z0tP6AY+sM3B4nko3uA4FrRJ +2nrrZPBtJoFBz5+D0A95qkbHWyxRdIv5HFOJeVMCbzQO0fyFDSMoahb7uvYfDho lOCVhQtCdZhh36C4SEdd9dCrteM5RkZMlAdIzDOqHn0NICBuP8XHerUgg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvddvjedgjeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tddunecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepgfehhefgudefudfgfeelgeei ffegfefhkeefffdvheefuddtheetgeelteevkeetnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 15 Mar 2023 00:57:32 -0400 (EDT) Date: Wed, 15 Mar 2023 13:57:28 +0900 From: Michael Paquier To: Juan =?iso-8859-1?Q?Jos=E9_Santamar=EDa?= Flecha Cc: Pg Hackers Subject: Re: Fix fseek() detection of unseekable files on WIN32 Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="fUSNfDmcg3JlTT4H" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --fUSNfDmcg3JlTT4H Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 14, 2023 at 01:26:27PM +0100, Juan Jos=E9 Santamar=EDa Flecha w= rote: > As highlighted in [1] fseek() might fail to error even when accessing > unseekable streams. >=20 > PFA a patch that checks the file type before the actual fseek(), so only > supported calls are made. + * streams, so harden that funcion with our version. s/funcion/function/. +extern int pgfseek64(FILE *stream, pgoff_t offset, int origin); +extern pgoff_t pgftell64(FILE *stream); +#define fseeko(stream, offset, origin) pgfseek64(stream, offset, origin) +#define ftello(stream) pgftell64(stream) What about naming the internal wrappers _pgfseeko64() and _pgftello64(), located in a new file named win32fseek.c? It may be possible that we would need a similar treatment for fseek(), in the future, though I don't see an issue why this would be needed now. + if (GetFileType((HANDLE) _get_osfhandle(_fileno(stream))) !=3D FILE_TYP= E_DISK) + { + errno =3D ESPIPE; + return -1; + } Shouldn't there be cases where we should return EINVAL for some of the other types, like FILE_TYPE_REMOTE or FILE_TYPE_UNKNOWN? We should return ESPIPE only for FILE_TYPE_PIPE and FILE_TYPE_CHAR, then? -- Michael --fUSNfDmcg3JlTT4H Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmQRUDgACgkQnvQgOdby QH11BhAAhHK9CrqQOp430YBWFzmZ9+S7rV3kq1RIH4B7Ihr3/bl4LAvme8ulnbmg gAvtJIePG6E67RICc3jHc0Garjy9uEN/y7rmXGoz9Sf2d4YHnqQK00K2LRq6qJ+y ocmBRgNKJmwRidXeDUdUml+82ozIBoo4B8fGforRNvQUC4yYo0N+V5fW4AT8Jhdf N5DN1iG1KnFfeOHiHE+hqiuW8HDkMmy3CZuBt2Cwg/DBsvPEIyeKzhJQ70U8ljXm z19CxUVYKfnuVEEnof4+jrlpliueryUR3gWVzm7QBwK5/1olsQ3bn7HrK3+l55hH rNOw1N7xO5tj66c7ed76K376yOgeytPGqvFRRUsrgpy9VRbCPjlaqOpzd7s+gptL J4Qpy0JIUoCNfCGB0GjpmSTs4ymlsi0MG+/cPkU2fVhvWM5vAlKI4KKXGZhtw8Vo dtAIVL6qGZO+SyeArcERxUB2wD9h6E8qEpOZJsqsN7V5laL6CEN2/FeWXhnoxOFn qQ1s7DivyLBQu/+qyMydU54w/Wrr+1OGCh9k32ruVs4us6H3vUOLfXPsAccGegPU 7bCvL/54cIDz4zBQgEFhTXruHFFQ17N1PJOErfv3gW7sb60Rnv4JiI182TH8honQ LQN2JDcp6b+b/g+lE6LHiKhaAQBdf+/hSmR+dQAIpkgaeTCsNp4= =LOuR -----END PGP SIGNATURE----- --fUSNfDmcg3JlTT4H--