Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s4Bjc-001UrB-JC for pgsql-hackers@arkaria.postgresql.org; Tue, 07 May 2024 03:43:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s4BjZ-000GP8-Lj for pgsql-hackers@arkaria.postgresql.org; Tue, 07 May 2024 03:43:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s4BjZ-000GP0-C2 for pgsql-hackers@lists.postgresql.org; Tue, 07 May 2024 03:43:18 +0000 Received: from wfhigh8-smtp.messagingengine.com ([64.147.123.159]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s4BjX-001wRV-CC for pgsql-hackers@postgresql.org; Tue, 07 May 2024 03:43:17 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfhigh.west.internal (Postfix) with ESMTP id 507091800122; Mon, 6 May 2024 23:43:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 06 May 2024 23:43:12 -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:subject :subject:to:to; s=fm3; t=1715053391; x=1715139791; bh=u3ICaXsZbZ kQMK3iyX0CBnWKw02iqcE+WUFrxw+OsOU=; b=VpWB5dG07eEf6oWBnu7Ffr7rcS DirE3fYQOjvIzF0lDXk0HcJNFvg8aoNnMq1lx0GAz/Igx5ft5tqwGVhnJdtIiOsZ a2kEBQoWAV7YBv9OLg1K6HB6CRN/U1JPK9TC8jxITcryPmXkKjN73rxaWYXwOOLe PHpR/OsnkxGV148gqJedCvNLrQHN6gHoFQ+oST2jfbu15+p55QCkVk/wUzZxTcVz icKGJ/60dRIOp72YXubVqiXzFgUfDex0UfPKMZlfQAru3XNMmainBsfVAHmzxKn/ C05ZPxSn2f3e3s1IZp7w7YUxPrG75fh3Me1qoEkZpyTSjSYwfqt/iGa6HEow== 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:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1715053391; x=1715139791; bh=u3ICaXsZbZkQMK3iyX0CBnWKw02i qcE+WUFrxw+OsOU=; b=ZPrGvn5Jmq/DarKJprpb0ay2xuAE1zXJ02wsUd1lsjxz hjQC2tc6QHsnDrmKNGtKmZs7ia6izQEzdCXBt01sWhnXa7b+dKr5hrWjw9pmZWIo hhyUr4AXn1t+xKNAxX5a9kdoEYdVj5NqwxUx4Ft3PaH5599CSsefaiHOWzY/ZaYk 6/K//7mzlpmccfJ+iAf1uGndhNE5f5dTIFYPS0/CU6VuqC3fVrhiBoDi1zxh7mDj J/sIkn4BfMx73uq9NMdqULNqVRNWOzVKskv4X100KcyI3XZt9+iyS0bsPWTWoubU Kysx2cHacXuy64RQKHjtITPLZ+zIsqeDPC3Pj7HboQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvjedgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdlfeehmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tdejnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepveetjefgjeevgedukeehieeu ieeuieevueeiudegheevuefggfduueelgeelieetnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 6 May 2024 23:43:09 -0400 (EDT) Date: Tue, 7 May 2024 12:42:55 +0900 From: Michael Paquier To: Jacob Champion Cc: Peter Eisentraut , PostgreSQL Hackers , Andrew Dunstan Subject: Re: [PATCH] json_lex_string: don't overread on bad UTF8 Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="IruD35y1Xu5/6nhu" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --IruD35y1Xu5/6nhu Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, May 03, 2024 at 07:05:38AM -0700, Jacob Champion wrote: > On Fri, May 3, 2024 at 4:54=E2=80=AFAM Peter Eisentraut wrote: >> but for the general encoding conversion we have what >> would appear to be the same behavior in report_invalid_encoding(), and >> we go out of our way there to produce a verbose error message including >> the invalid data. I was looking for that a couple of days ago in the backend but could not put my finger on it. Thanks. > We could port something like that to src/common. IMO that'd be more > suited for an actual conversion routine, though, as opposed to a > parser that for the most part assumes you didn't lie about the input > encoding and is just trying not to crash if you're wrong. Most of the > time, the parser just copies bytes between delimiters around and it's > up to the caller to handle encodings... the exceptions to that are the > \uXXXX escapes and the error handling. Hmm. That would still leave the backpatch issue at hand, which is kind of confusing to leave as it is. Would it be complicated to truncate the entire byte sequence in the error message and just give up because we cannot do better if the input byte sequence is incomplete? We could still have some information depending on the string given in input, which should be enough, hopefully. With the location pointing to the beginning of the sequence, even better. > Offhand, are all of our supported frontend encodings > self-synchronizing? By that I mean, is it safe to print a partial byte > sequence if the locale isn't UTF-8? (As I type this I'm starting at > Shift-JIS, and thinking "probably not.") > > Actually -- hopefully this is not too much of a tangent -- that > further crystallizes a vague unease about the API that I have. The > JsonLexContext is initialized with something called the > "input_encoding", but that encoding is necessarily also the output > encoding for parsed string literals and error messages. For the server > side that's fine, but frontend clients have the input_encoding locked > to UTF-8, which seems like it might cause problems? Maybe I'm missing > code somewhere, but I don't see a conversion routine from > json_errdetail() to the actual client/locale encoding. (And the parser > does not support multibyte input_encodings that contain ASCII in trail > bytes.) Referring to json_lex_string() that does UTF-8 -> ASCII -> give-up in its conversion for FRONTEND, I guess? Yep. This limitation looks like a problem, especially if plugging that to libpq. -- Michael --IruD35y1Xu5/6nhu Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmY5oz8ACgkQnvQgOdby QH0lCg/9FOiIin17mX6riAkgPZUU8Oiagf5nHRCwZfLvv1TyCCLS5R+gTHQP8oBq d4E63iFdgGvoCsWY/ZVVwPiOkMtRRtxSskpQwyBqTGv5f40I/QKRIH9vaO4sNK7p 0xBZNZQhIwmofvPxXkSRFfxYS+45+cBtbj7IgPPr5oLa1oyjV1yvmUwvyd6CGnoL GjmHYODB4kG/ibh35t0UGccCvFSz+NxC0aMS4zaSy4ISYQBkwrxoSYta/kY0nKcN /5xuaFE6mwsnH2dzRxy5g4cA7HZv0NYqm4jrl70si8h2JabUtYkrq1GzUJNH7UdN 6ueN0+O3u6oztMxlPkeiWz5XU814zdX7O6WP25UdgZ4cfyiJ7AvsEWt6VS/VP1vI VbJ/24Rw66GI9MWUynYj5ZWsew68O9HwUbN8sMPj9u7sbZUQsoBrubabaUztCret 2YMreq88S/1aSNy8cW5T+qG12QtCaAHt5Xwp5W/g49U54JXcl5wWlRn7qYp5hWkX 7zXEVm7yVc3sVbiANnJD028NSiaHAVMJ+SJiKs+UpNPuLDBmn9701tTrkImTvtYE C7k1HZMZ3ifOqZ4kmOgYwwWIOVlqyt5UqjDgF9EaCTsfXAmsvEFjf7+QvwjRsU0M ClHwU8mtfKaYWvXOw6QECtnBRI/wFP7ifp08kykQM5ET7Xy+/oc= =f6z+ -----END PGP SIGNATURE----- --IruD35y1Xu5/6nhu--