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 1poKWb-0007FC-6p for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Apr 2023 08:47:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1poKWa-0007ZV-1k for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Apr 2023 08:47:48 +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 1poKWZ-0007ZL-OL for pgsql-hackers@lists.postgresql.org; Mon, 17 Apr 2023 08:47:47 +0000 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1poKWY-003OEy-67 for pgsql-hackers@lists.postgresql.org; Mon, 17 Apr 2023 08:47:46 +0000 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-63b52ad6311so1365568b3a.2 for ; Mon, 17 Apr 2023 01:47:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681721263; x=1684313263; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=LDokgI9V73YU/W5Q4z0t+T7GlPJ/7KdhIgDfuW2JCx4=; b=ne5P2D5i4J6a18++VMaBE814xll1XrmRfvn57rtt2Piz/1Pc7dUClxLXUQq0xw4eb5 TUPONUPwsveyLTWr2EOOFSjQC8gIbLTTlghxn+KZBcZlOZSdOP1IFCRUup2gVnCgoK2R PPmaPQxQJ1VKXeNGawF+niqr+bmu+psy+kJKaXuEmOftXcipeb5Zj5UrY1Ie+U+7GLaI FZLf1UXfq5HAcYTWJ13HehMUKtdEOnazVu22Y4ZXWAsdFQG10DctEjjXifzYJBKQoKab xpsE+Vu+8nX4sD+kX3KxG8UafOdMIUio3UM4yf30h48jLJyahHkh4eCIdu2vuNy2TiAF tqTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681721263; x=1684313263; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:from:subject:cc:to:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=LDokgI9V73YU/W5Q4z0t+T7GlPJ/7KdhIgDfuW2JCx4=; b=bGRi4OrkY/3WteOGFyBzNTR3ijLhxTqyTElLySflNkW+Lp906o5QHzGdFfpBDiHlAL Xdo5B+3jhFChx4XY07iYmLnXeuHZEdkJe6o0B3660aaiuPZF1xuZ0y4xNZiwRVDxRpto tG0OKgCPVluKRObavICy7YnqjWv+oDtPn8bTlqwNdFTJPeWliqYBePiDqYJC8dQgDdxU QCBNqV5ZdT6Lqq/NQeBdAU8Q7mMFYqxbxk2gx1fE4KjIZdUScK7lB6h9N1LRfpOe3W5n mBysbE7Ko/i+X9amh5lg+OxYdr6qgGqoLPrKzMDBLtPKdL/CGn6pP2bUAG2oEzJU6pql vB0w== X-Gm-Message-State: AAQBX9eE3LYSHjexhrYRKscO/OyUkjvJESOivOvSGJ+H37g4uJmjDU/E HGcpMq8i9SAKKxY3bqIzRSA= X-Google-Smtp-Source: AKy350aiiiwh0kKktuqupSnqWkl2ufnjDbu/xFBDQ7UBGuMps2som3CihoYrFpkvfG4wxnyP24Mr7A== X-Received: by 2002:a05:6a00:1a09:b0:636:e52f:631e with SMTP id g9-20020a056a001a0900b00636e52f631emr19000505pfv.1.1681721263700; Mon, 17 Apr 2023 01:47:43 -0700 (PDT) Received: from localhost (KD036014041111.ppp-bb.dion.ne.jp. [36.14.41.111]) by smtp.gmail.com with ESMTPSA id p15-20020a62ab0f000000b0063d2989d5b4sm671079pff.45.2023.04.17.01.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 01:47:43 -0700 (PDT) Date: Mon, 17 Apr 2023 17:47:41 +0900 (JST) Message-Id: <20230417.174741.829927450239624934.horikyota.ntt@gmail.com> To: michael@paquier.xyz Cc: pgsql-hackers@lists.postgresql.org Subject: Re: eclg -C ORACLE breaks data From: Kyotaro Horiguchi In-Reply-To: References: <20230410.173500.440060475837236886.horikyota.ntt@gmail.com> User-Agent: Mew version 6.8 on Emacs 27.2 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk (sorry for the wrong subject..) At Mon, 17 Apr 2023 17:00:59 +0900, Michael Paquier wrote in > 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. Thanks for picking this up. regards. -- Kyotaro Horiguchi NTT Open Source Software Center