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 1poJnZ-0004nO-U7 for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Apr 2023 08:01:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1poJnY-000265-R9 for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Apr 2023 08:01:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1poJnX-00025w-7u for pgsql-hackers@lists.postgresql.org; Mon, 17 Apr 2023 08:01:16 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1poJnS-000HZ7-Lo for pgsql-hackers@lists.postgresql.org; Mon, 17 Apr 2023 08:01:14 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id B94CC5C0106; Mon, 17 Apr 2023 04:01:08 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 17 Apr 2023 04:01:08 -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=fm3; t=1681718468; x=1681804868; bh=6S YmzKkYlGk7M3rr3Oyu5HTqLsxk84Pc6ATk2Cdm5Mo=; b=0GHTRwF339ZQ000XBo oDAUppmehx+sPevIXvVO3OBRQxTvAl1Py9vT2rfzL9ze8Dh8ifrCYQoewtETUJNp CUFRsSTllFDXdPQT58ugMRSaP8tyaPDbvjhRb1fIj86cuD2Yynigw+qja+g4tKsY 2IexIFA+jqNrXaIXYKUnDFGtfMq2YWII04Nk0qijwBjAuanlGYaN3uh0QQrTjO2a E4PJxGDfyskJS+g5qHfNZ8jM2MRtHFXQjMF98DI2/SRTvb7w56qAx/kzbSaX4i5K bHLvnAMWlwx4GEsC5aBT5zel+QMpPcwkLNXg+WJSJAyutvlnHXClxOx+8pPIKRDV v6Pg== 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=fm3; t=1681718468; x=1681804868; bh=6SYmzKkYlGk7M 3rr3Oyu5HTqLsxk84Pc6ATk2Cdm5Mo=; b=Iat/ONB8xvYCwC7sCzpQTg4tOqvaM bpDHhU/wz+i3Lh2JNj3sGFxZpAlbsdPByWLl4VtVmCbSzxMHg1iBtqGQD6JYkWWX vBkkJx+ufH25p/V1Jc9V5ynwRAmZSDpXf5cAjwY05W+9xj5+O4hdt6x9DR/n1Iah +Lk8a0j5fyleXZNgUHBn3Sr+qaO+uwBrgp1RXgcoPjoK+0tpbLCRLnLz/ppw1axD Gu9fikUD0qwg2VsXY6Tu5G1a1rEdtqar2VkIJawE7LYTALWTL8FxlSSkN4WWY6m7 kjiuKbsKcsvX2jQ5Y5xqhU4piEHyu3AnzXuyN1VJVftLzaEWus8u6krKg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdelhedguddvkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhepff fhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgr qhhuihgvrhcuoehmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtth gvrhhnpeetleeifedufffhhfdtteelgeeggeffhfekueevteeigfduudevudetgfegiedv jeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmih gthhgrvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 17 Apr 2023 04:01:06 -0400 (EDT) Date: Mon, 17 Apr 2023 17:00:59 +0900 From: Michael Paquier To: Kyotaro Horiguchi Cc: pgsql-hackers@lists.postgresql.org Subject: Re: eclg -C ORACLE breaks data Message-ID: References: <20230410.173500.440060475837236886.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="CkUq6Dy9GWog6ivg" Content-Disposition: inline In-Reply-To: <20230410.173500.440060475837236886.horikyota.ntt@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --CkUq6Dy9GWog6ivg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Apr 10, 2023 at 05:35:00PM +0900, Kyotaro Horiguchi wrote: > This results in overwriting str[-1], the last byte of the preceding > numeric in this case, with 0x00, representing the digit '0'. When > callers of ecpg_get_data() explicitly pass zero as varcharsize, they > provide storage that precisely fitting the data. Good find, that's clearly wrong. The test case is interesting. On HEAD, the processing of the second field eats up the data of the first field. > However, it remains > uncertain if this assumption is valid when ecpg_store_result() passes > var->varcharsize which is also zero. Consequently, the current fix > presumes exact-fit storage when varcharsize is zero. Based on what I can read in sqlda.c (ecpg_set_compat_sqlda() and ecpg_set_native_sqlda()), the data length calculated adds an extra byte to the data length when storing the data references in sqldata. execute.c and ecpg_store_result() is actually much trickier than that (see particularly the part where the code does an "allocate memory for NULL pointers", where varcharsize could also be 0), still I agree that this assumption should be OK. The code is as it is for many years, with its logic to do an estimation of allocation first, and then read the data at once in the whole area allocated.. This thinko has been introduced by 3b7ab43, so this needs to go down to v11. I'll see to that. -- Michael --CkUq6Dy9GWog6ivg Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmQ8/LsACgkQnvQgOdby QH0qmhAAia0XTL4U7o4p+3Mki98ipYkWdfzqkEcg3Ey3qW2eMicQXS6+FjGTNApp 0GYxJvOXPlNtgcgdMXm1KTnLCwIONVtJTauYALRrKV71zu4cqqX+EO4mRdZmgMA0 TpNO/MuonhFQF3ePW/DAJg4tWtq+q+kHylnEnD70jZAj2rqFth1HN6AnoM9dLrIs xX238uICz8p+m+Uw9G4QZvC7mwUUUW9AwMKK6KozIZUYH9slWVYqz50OqtxWNDz2 CD+a6VDLQSCsASG07icwIZPnPom7coEy0wnMt0iVn4ASigpvmE7qhJOacFkRsBmu qmNRAIuds73Bs1pExuNbdEi1vZp5ir0l9gHW5Mtcg48yZXuwO+795sbZ/8778u0L Bsf6G0X6wINIsfDNHVjMCP/CdbCNGF6W5nPC1qq8GdZiJ4BqWGH3q/u8MrtdJTGh ZiQ+Mj7nBc+0CSXuACcc+czS/QE/3qxmUdQTVifShqzvT+LVzg10wZjK/CfgezDF st1hELP4Z6A9K4pyxfpy75UguL6KoBS1AWJGZ/4roLDMXos55lb/aNrif4U/h+68 tkQIkcAl9+LGk0TTc4sQtInrbEJhrFbUGyo0p/Iag7bInXdCt9uFmpkGwfq2U3zU FFzhnzhPoS4NlFmrnrY2in5BC44sain3QuPQ35o1oQQ+sK1hYnA= =eJBo -----END PGP SIGNATURE----- --CkUq6Dy9GWog6ivg--