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.98.2) (envelope-from ) id 1xR5j2-00000000fn8-34gN for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Nov 2026 10:38:44 +0000 Received: from localhost ([127.0.0.1]:44518 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xR5iz-0000000AE0t-1SNu for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Nov 2026 10:38:41 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:55858) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR118-00000008qDn-3oQd for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 05:37:07 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR117-00000000Jpb-3j8J for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 05:37:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=HIz/2QOi3AcxRsCHIZ37KlQ9WqqcyGk+ZKZ0BhmBseI=; b=dclx3EIXeBBjKufN0bbS9Nu1M3 a4FBxTzv0/kWkCTmeGYO13MvXpByilIKjin/jBCcmOFE4U0QSv7aeHAf08A34THk3SPygGE4p4NGl 1BwCG6yGftGSzsrn+ZjOsz+AdwluGEvxWCWGCKqPrUIZpSCgv6lu1Vei9kyMkMp28CUIVDyYGfB84 9IiYtw18/P03Ai0yWIXNGAgjmJZtAdir4T59RlJ8VJf8wR+DgWi+aHJw9NrwGc7CcQ25+j2k7NpXD vwUV9QBFnsHlFxLTizaWBX8lGgZwCf4WYfW0pRz5LzSq8z09vaGGJMxzyCNbrPMMOxjADb3gSDiKC TABx4/ZA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xR116-00000000swE-2wl8 for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 05:37:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xR115-00000002IXv-3t0l for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 05:37:04 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19865: WAL summary reader wraps block numbers for oversized chunk counts To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: imchifan@mail.com Reply-To: imchifan@mail.com, pgsql-bugs@lists.postgresql.org Date: Wed, 11 Nov 2026 05:36:09 +0000 Message-ID: <19865-b30f75a4530db87d@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19865 Logged by: Faye Email address: imchifan@mail.com PostgreSQL version: Unsupported/Unknown Operating system: Linux/amd64 Description: =20 pg_wal_summary_contents() accepts a checksum-valid WAL summary containing 65,537 chunks. When chunks 0 and 65,536 both contain offset 7, it returns block 7 twice. The second entry mathematically represents block 2^32+7, which is outside the 32-bit BlockNumber domain, but the reader wraps it to 7. The reader should reject this summary because its declared chunk domain represents block numbers that BlockNumber cannot express. It should not return aliased block references. How to repeat: ```python #!/usr/bin/env python3 import shlex import struct import subprocess SUMMARY_NAME =3D "00000001FFFFFFF000000000FFFFFFF000000001.summary" TABLE_NAME =3D "wal_summary_test" def crc32c(data: bytes) -> int: crc =3D 0xFFFFFFFF for byte in data: crc ^=3D byte for _ in range(8): crc =3D (crc >> 1) ^ (0x82F63B78 if crc & 1 else 0) return crc ^ 0xFFFFFFFF def make_payload() -> bytes: # One relation entry with chunks 0 and 65536 both encoding offset 7. # The latter block number is 2^32 + 7 and wraps to 7 in the reader. body =3D bytearray(struct.pack(" str: result =3D subprocess.run( ["psql", "-X", "-v", "ON_ERROR_STOP=3D1", *options], input=3Dsql, text=3DTrue, capture_output=3DTrue, check=3DTrue, ) return result.stdout payload_hex =3D make_payload().hex() setup =3D f""" CREATE TABLE {TABLE_NAME}(lo oid); INSERT INTO {TABLE_NAME} SELECT lo_from_bytea(0, decode('{payload_hex}', 'hex')); SELECT lo_export(lo, current_setting('data_directory') || '/pg_wal/summaries/{SUMMARY_NAME}') FROM {TABLE_NAME}; """ test =3D """ SELECT count(*) AS rows_returned, count(DISTINCT relblocknumber) AS distinct_blocks, min(relblocknumber) AS min_block, max(relblocknumber) AS max_block FROM pg_wal_summary_contents(1, 'FFFFFFF0/00000000', 'FFFFFFF0/00000001') WHERE relfilenode =3D 12345 AND NOT is_limit_block; """ run_sql(setup) try: print(run_sql(test, "-A", "-t"), end=3D"") finally: data_directory =3D run_sql( "SHOW data_directory;", "-A", "-t" ).strip() summary_path =3D f"{data_directory}/pg_wal/summaries/{SUMMARY_NAME}" remove_command =3D "rm -f " + shlex.quote(summary_path) cleanup =3D f""" COPY (SELECT 1) TO PROGRAM '{remove_command.replace("'", "''")}'; SELECT lo_unlink(lo) FROM {TABLE_NAME}; DROP TABLE {TABLE_NAME}; """ run_sql(cleanup) ``` Run it as a role permitted to call lo_export(), COPY TO PROGRAM, and pg_wal_summary_contents(): ``` python3 reproducer.py ``` I get: ``` 2|1|7|7 ``` The query therefore reports two rows but only one distinct block number; both the minimum and maximum are 7. The serialized entries represent blocks 7 and 2^32+7, so the latter has been wrapped rather than rejected. The issue was reproduced on PostgreSQL 20devel on Linux/amd64. BlockRefTableReaderNextRelation() limits nchunks by allocation size, while BlockRefTableReaderGetBlocks() computes chunkno * 65536 + chunkoffset in the 32-bit BlockNumber domain. This occurs when reading a malformed, checksum-valid WAL summary whose declared chunk domain extends beyond the range representable by BlockNumber.