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 1s4Ztc-005NpS-Kw for pgsql-hackers@arkaria.postgresql.org; Wed, 08 May 2024 05:31:17 +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 1s4ZtY-0070jL-Dr for pgsql-hackers@arkaria.postgresql.org; Wed, 08 May 2024 05:31:13 +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 1s4ZtX-0070jD-4N for pgsql-hackers@lists.postgresql.org; Wed, 08 May 2024 05:31:13 +0000 Received: from fout4-smtp.messagingengine.com ([103.168.172.147]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s4ZtP-00274k-In for pgsql-hackers@postgresql.org; Wed, 08 May 2024 05:31:11 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 30CD01380FE7; Wed, 8 May 2024 01:31:01 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 08 May 2024 01:31:01 -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=1715146261; x=1715232661; bh=HB0yYs31mn aGTixbd8XBX2iNREHOvlxuSyBZdUfiw9I=; b=QleA3wpg/tP1KbbjZp3mkZoSjO 6Om1piBXtSLgDl8MVDE+Cmdz0Rpj8Y7cmGVntEgy37qO5jQMYrCwjg34hqkkrMA5 5MIl5tkdEhutBXmmRPar9Zn/7dPLxXYnBW2MSIn+cLSt+fnVVLD/Kxjx+mKV90A4 /FcKRHVd1amHi7EggZH+QCSHdyT6ts+AJ4HEy2gCMnoVm3j+hwpETdEQ8vima1yH Y8HacyoJadsHA16K5z1qiZz4D9u2e+x5LQ+ExNI7iyGwCHCmexZGDSK8HiImrViT V5Ax4KPs6QYezE5csEePOo1lrYE8TniSfq42kfq/qbcthpGwIDkO5Q1gc5lQ== 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=1715146261; x=1715232661; bh=HB0yYs31mnaGTixbd8XBX2iNREHO vlxuSyBZdUfiw9I=; b=XiNwoGbKVmvhVCEnEy3cBGwkQRUmkjPIiKJvWwIKmKSL Lvj33ZOa5QRwCYr17c0go6tfymnZQ9OY7jHLnRfb8a745rrKxGN7ic8TnCgcFK2C 6WHLvR1cPA/eInoxZfLFYzPBNFqEOZN0vhv+atngnP5dW4n/jeD++OflnDiSpMqN KbpAtgV36DkPGFhvaV0OsDKshj2B2SF1X1b0TrxnqN7Le/KnX1J4mJ06vZrBYa8M +m+tcrW36NlAknV9MDv2cD5599dGTFNFbrrckVNahtCqsHp94X0HneYGRAcHITpc 6N8tr9e/z9idgZQ4b8AaxH3P7ZduSsZ6AS5N/SrQpw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvledgledvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeg geegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 8 May 2024 01:30:58 -0400 (EDT) Date: Wed, 8 May 2024 14:30:43 +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="T9uO6tHG+jfv4sA1" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --T9uO6tHG+jfv4sA1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, May 07, 2024 at 02:06:10PM -0700, Jacob Champion wrote: > Maybe I've misunderstood, but isn't that what's being done in v2? Something a bit different.. I was wondering if it could be possible to tweak this code to truncate the data in the generated error string so as the incomplete multi-byte sequence is entirely cut out, which would come to setting token_terminator to "s" (last byte before the incomplete byte sequence) rather than "term" (last byte available, even if incomplete): #define FAIL_AT_CHAR_END(code) \ do { \ char *term = s + pg_encoding_mblen(lex->input_encoding, s); \ lex->token_terminator = (term <= end) ? term : s; \ return code; \ } while (0) But looking closer, I can see that in the JSON_INVALID_TOKEN case, when !tok_done, we set token_terminator to point to the end of the token, and that would include an incomplete byte sequence like in your case. :/ At the end of the day, I think that I'm OK with your patch and avoid the overread for now in the back-branches. This situation makes me uncomfortable and we should put more effort in printing error messages in a readable format, but that could always be tackled later as a separate problem.. And I don't see something backpatchable at short sight for v16. Thoughts and/or objections? -- Michael --T9uO6tHG+jfv4sA1 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmY7DgMACgkQnvQgOdby QH3/Bw//Ro2FSclAApcTu4gIR8mImxcM1OBiWgvYDPvQV9u1X0ObiA/IQ4mTrzqn IW53hblo8Eh7emGViN5xD9JDlahJAOCGEr2DAYMW/3cksUwqXmsYdbs/Q3l58XkE iL6DLiGfsCSI3hLuluNFbWOp74PFZj9/xt6WAnVrM8BcvtxhAim/qXqrpMRXJCDB D3KM5tLRWhXLtGLraWuUUtwuGgBRf2o17z0NY3qBAuwcQuefdPQSwPYVogU5itMw 8fAk+e8wtKxD6FVRoIix66WGBKlwmc/CGegVaJzS+lS3UHT5/+KLsIf39CG1TF1X C+qkcSEcXv3g/XX4isOUpWff8ISnmJYqhF6hKzYrUV9urCSLfNbwELqwvI0BOipr 0W+tf/Or7chIGggjijB+I2fVGhzrgroDbdKEoEA88VZDS9ihbSyHJ3+b75Q7t8op nOHtSNF1aSyOZgww0y/6SFISstNW/FqS5vBM5BpzfbZw9XrntzxmbCvCZceQ/3mJ /XoJVpjsmd1bi2r9xvPkq2JrU4vQYWPRLcULlFYYgWkezjVgZhzc3tEMD3Y7+QKJ xYk4N5nDGSVlVTlFJCyclRnW5ULCeB60kqIKd8oiGvPo0AzrbiNgn0MnG9JNi3/R 2gdPNrfEQ3TPH81YByXavTLXE+NLCPWe9eNR7soG+AS31L2Q0qI= =aXLJ -----END PGP SIGNATURE----- --T9uO6tHG+jfv4sA1--