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.96) (envelope-from ) id 1wMKFF-002Ny2-2L for pgsql-hackers@arkaria.postgresql.org; Mon, 11 May 2026 06:36:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wMKFE-00GMYP-0k for pgsql-hackers@arkaria.postgresql.org; Mon, 11 May 2026 06:36:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wMKFD-00GMYF-1A for pgsql-hackers@lists.postgresql.org; Mon, 11 May 2026 06:35:59 +0000 Received: from fout-b2-smtp.messagingengine.com ([202.12.124.145]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wMKFA-00000001EiP-2lxF for pgsql-hackers@lists.postgresql.org; Mon, 11 May 2026 06:35:58 +0000 Received: from phl-compute-09.internal (phl-compute-09.internal [10.202.2.49]) by mailfout.stl.internal (Postfix) with ESMTP id D2B351D0008F; Mon, 11 May 2026 02:35:55 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-09.internal (MEProxy); Mon, 11 May 2026 02:35:55 -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 :message-id:mime-version:reply-to:subject:subject:to:to; s=fm3; t=1778481355; x=1778567755; bh=+cXQ5DXWN3H3NAKG/7bWu3R0QQZ+7Rdg XKkTP4DdIu4=; b=EAm0AaiOHIRB4CSR2ldXu02sFlZmyl6/wq786QnvtrT50Tn6 xYdQ1bPU0deqe2xo13Y3WHo52Mjl30isAEOyqFNZq4eOwM4W1gbA/xkqW2pmGOsE MPPlqDCy18IvFujPl1Yi9QPQ0UZtawe7dRtmuh4I6xBGFwBGZR6KsugJ1gKBVZbk IdoOFNX4qtLzGbLIlt5Zt7AnQ4ceIsfiGE7h0O75kydpcLSaCbTKqMuB5iRgJrGg V1J0Mh2PWi9dySjC+3Kv91HaYAUTbBlkR8e6kODRvC3NRB6pASKSd614pt1GRKWl Bd/lgNhcZAyZrz4F3Qjltj1LFolwlar2uOtl0A== 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:message-id :mime-version:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1778481355; x= 1778567755; bh=+cXQ5DXWN3H3NAKG/7bWu3R0QQZ+7RdgXKkTP4DdIu4=; b=v fDB95GICkHqW8uchhHXL3TtuBqxAEbVU6VWOetb7pO5c2Mm6ErYLb7ogl2K4Ltuh jpinsNonVfyCEojqUPBrS1PTFZweIaWceOkki3gh+VIV+6NDFoFQ09wDp83iYkZW dI3wHZ+4d33YwScd7xFG+iaE+X4krBslH+LAbKHRGlL6S6aGmvGhmbY70ff4kG2n YngG0Baft8LIFc7nai9R/uNvbNDpL+S78YIVk718U3za/qi1SgzyeAsuxymHg7xy gDh7qrOsHNCvanoXyERDqXzF1bidZfEZNMwy+jH+UTi7ABqcXZr72g9gAhHv451y 6IK9LxTk5GwH9YqSDapzA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdduudekvdejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrh hlucfvnfffucdlfeehmdenucfjughrpeffhffvvefukfggtggusehgtderredttddvnecu hfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqhhuih gvrhdrgiihiieqnecuggftrfgrthhtvghrnhepgfethfduhffhtdeiheefffefleduleei keekvdegffehgeetjedutdeffeeuudetnecuffhomhgrihhnpehpohhsthhgrhgvshhqlh drohhrghenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhm pehmihgthhgrvghlsehprghquhhivghrrdighiiipdhnsggprhgtphhtthhopedvpdhmoh guvgepshhmthhpohhuthdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhs thhsrdhpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopegrnhgurhgvfiesughunh hslhgrnhgvrdhnvght X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 11 May 2026 02:35:54 -0400 (EDT) Date: Mon, 11 May 2026 15:35:50 +0900 From: Michael Paquier To: Postgres hackers Cc: Andrew Dunstan Subject: Plug-in coverage hole for pglz_decompress() Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="fIcYR/S1JVdRCjOT" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --fIcYR/S1JVdRCjOT Content-Type: multipart/mixed; boundary="svOz4+RxsXW240wN" Content-Disposition: inline --svOz4+RxsXW240wN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, (Andrew in CC, in case.) While doing a post-commit review of 67d318e70402, I have noticed the following coverage hole in pglz_decompress(), where a failure of this check is not covered, see also [1]: if (unlikely(off == 0 || off > (dp - (unsigned char *) dest))) return -1; This can be triggered easily with the two following sequences in the regression tests: SELECT test_pglz_decompress('\x011001'::bytea, 1024, true); SELECT test_pglz_decompress('\x010300'::bytea, 1024, true); It's unfortunately too late for this round of minor releases, but I'd like to fix this hole once the next minor versions are tagged, down to v14. If there are any objections or comments, feel free. Mea culpa. Thanks, [1]: https://coverage.postgresql.org/src/common/pg_lzcompress.c.gcov.html -- Michael --svOz4+RxsXW240wN Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=0001-Add-more-tests-for-corrupted-data-in-pglz_decompress.patch Content-Transfer-Encoding: quoted-printable =46rom 4a63b443e241e98df27489ac04291822f4a56bc5 Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier Date: Mon, 11 May 2026 15:21:30 +0900 Subject: [PATCH] Add more tests for corrupted data in pglz_decompress() Two cases fixed by 2b5ba2a0a141 were not covered, emulating corrupted data: - Set control bit with a valid 2-byte match tag where offset is 0. - Set control bit with a valid 2-byte match tag where offset exceeds output written. Oversight in 67d318e70402. Backpatch-through: 14 --- src/test/regress/expected/compression_pglz.out | 12 ++++++++++++ src/test/regress/sql/compression_pglz.sql | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/test/regress/expected/compression_pglz.out b/src/test/regr= ess/expected/compression_pglz.out index 0ef49d425068..066a3317c65d 100644 --- a/src/test/regress/expected/compression_pglz.out +++ b/src/test/regress/expected/compression_pglz.out @@ -60,6 +60,18 @@ SELECT test_pglz_decompress('\x010f01'::bytea, 1024, fal= se); ERROR: pglz_decompress failed SELECT test_pglz_decompress('\x010f01'::bytea, 1024, true); ERROR: pglz_decompress failed +-- Corrupted compressed data. Set control bit with a valid 2-byte match +-- tag where offset exceeds output written. +SELECT test_pglz_decompress('\x011001'::bytea, 1024, false); +ERROR: pglz_decompress failed +SELECT test_pglz_decompress('\x011001'::bytea, 1024, true); +ERROR: pglz_decompress failed +-- Corrupted compressed data. Set control bit with a valid 2-byte match +-- tag where offset is 0. +SELECT test_pglz_decompress('\x010300'::bytea, 1024, false); +ERROR: pglz_decompress failed +SELECT test_pglz_decompress('\x010300'::bytea, 1024, true); +ERROR: pglz_decompress failed -- Clean up DROP FUNCTION test_pglz_compress; DROP FUNCTION test_pglz_decompress; diff --git a/src/test/regress/sql/compression_pglz.sql b/src/test/regress/s= ql/compression_pglz.sql index a44af02afb7b..dbd37f7d4eb2 100644 --- a/src/test/regress/sql/compression_pglz.sql +++ b/src/test/regress/sql/compression_pglz.sql @@ -48,6 +48,16 @@ SELECT test_pglz_decompress('\x01ff'::bytea, 1024, true); SELECT test_pglz_decompress('\x010f01'::bytea, 1024, false); SELECT test_pglz_decompress('\x010f01'::bytea, 1024, true); =20 +-- Corrupted compressed data. Set control bit with a valid 2-byte match +-- tag where offset exceeds output written. +SELECT test_pglz_decompress('\x011001'::bytea, 1024, false); +SELECT test_pglz_decompress('\x011001'::bytea, 1024, true); + +-- Corrupted compressed data. Set control bit with a valid 2-byte match +-- tag where offset is 0. +SELECT test_pglz_decompress('\x010300'::bytea, 1024, false); +SELECT test_pglz_decompress('\x010300'::bytea, 1024, true); + -- Clean up DROP FUNCTION test_pglz_compress; DROP FUNCTION test_pglz_decompress; --=20 2.54.0 --svOz4+RxsXW240wN-- --fIcYR/S1JVdRCjOT Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmoBeMYACgkQnvQgOdby QH11Jg/7B92DaWTWITiLC6eJBqtclEsrHcIPIdFS/Psedon2LQ5sFcMG7MoJJkfG i+IJtLiFGnrz7f4k7Q74idu86A4iN6ksp1BGwjGV649hlMvxtOp1aeezD+hGJO4B 1gdraurowpl/rWPj0+58wNzjKYhaAsecj93AtMQGsi4+RJIX400hXp1AuEjfx/so EoZNQz3eUwFo+oDqcaXDgTQuc3dpC5QxDiXvu2jG+XV4DyTBs6p0gwDlYGgrTTvw ghltMSTuBHaT8yBcAFwb1TrMsX922VHiL1mavkdYU6quf8UrUjO1hdGosfoUTHpk CGOV0uFQbPnVxxVBt06tNlu4HJITLaJIvpFBeLfmaUR5AdjVKgQZDdUXWAvj/q/B TBZkkutIds1iOg5J2G7Cx0gYReAs1raKS7lC8uVTNZ2nUPVRolw+/oYFz/7kNg1E cHOs+Omp0KMprsm6Kg8Tcqntzw5rHReKp6OzAKTKuNxtZxTSxTNYkTun6MsEFAnJ Xy4Wj7dVgeUoC3jI7gvAYWn3aRnmFlbypAgdgHRdjDerNcpIamwSBoXLrfrxbIj9 CucXsOKXeQ+2oXvGPMGxBpRIGOCOxXgpSrKHO3ceD/06bYhjGPtkHTdd2yZa5v3I Q4nJpErIAO7p7uiL+im+cm/u3WX6fPaGXB1simzyA0WWk8ZWr6Y= =YwwB -----END PGP SIGNATURE----- --fIcYR/S1JVdRCjOT--