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 1wp3L2-001Ov6-34 for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Jul 2026 12:24:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wp3L0-005rUm-2E for pgsql-bugs@arkaria.postgresql.org; Wed, 29 Jul 2026 12:24:42 +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 1wosUq-003DGy-2z for pgsql-bugs@lists.postgresql.org; Wed, 29 Jul 2026 00:50:09 +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 1wosUo-00000000p8N-060L for pgsql-bugs@lists.postgresql.org; Wed, 29 Jul 2026 00:50:07 +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=dFnHvj/eWpu4dilJUJeaL90HhF1jg46N3s5xOY6Gghc=; b=S95bvv8OYY71Ul5QARC9e0D4cE lA3KeuaL3WBqyLODDwf4THZEWbbGNcVv+e75C1RSPo49fpHn9L+i3VbfYrrmhgrNjdOMBdin3ojXu GAL61hwDHeusR1UmkwYNayg0OnFUDC0nMyaDoUKfktk2nSj1qjta04kK4Dne82OLkhVw2UNxXmpnR 1d01+oTdJeZXTMCw928s4zBLB0Hj+BgJGa0bGvZElLUQKehzWByp/rXi2wSXgCGF+HS1CVr79dMlL qIMWfiobEcmzyHQdoDUy2ufIbNCZWIFv3i6a+JKZGD7LaJNEXVquBsVF+bRwyI69vUth6HcvNEcVg p7jWCyXg==; 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.96) (envelope-from ) id 1wosUn-002byn-1g for pgsql-bugs@lists.postgresql.org; Wed, 29 Jul 2026 00:50: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 1wosUm-000000065IK-0Qac for pgsql-bugs@lists.postgresql.org; Wed, 29 Jul 2026 00:50:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19583: macaddr input accepts octet fields longer than 8 hex digits To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: malis@pgrust.com Reply-To: malis@pgrust.com, pgsql-bugs@lists.postgresql.org Date: Wed, 29 Jul 2026 00:49:33 +0000 Message-ID: <19583-ca7c85d40164f18b@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: 19583 Logged by: Michael Malis Email address: malis@pgrust.com PostgreSQL version: 19beta2 Operating system: MacOS Description: =20 The macaddr input function accepts colon and dash-separated octet fields containing more than 8 hexadecimal digits, and stores a value different from the one entered, with no error. Steps to reproduce (psql, no ~/.psqlrc, freshly-initialized cluster, default configuration): SELECT version(); version ---------------------------------------------------------------------------= -------------------------------------------------- PostgreSQL 18.4 (Homebrew) on aarch64-apple-darwin24.6.0, compiled by Apple clang version 17.0.0 (clang-1700.6.4.2), 64-bit (1 row) SELECT '100000001:0:0:0:0:0'::macaddr; macaddr ------------------- 01:00:00:00:00:00 (1 row) SELECT '-ffffff01:0:0:0:0:0'::macaddr; macaddr ------------------- ff:00:00:00:00:00 (1 row) Identical results on the Debian-based postgres:18 Docker image. Expected behavior: both inputs raise an error. The first field of '100000001:0:0:0:0:0' has the value 0x100000001, which is not a valid octet (documentation, section 8.9, describes macaddr input as six groups of two hex digits, with the condensed forms as the only variants); the second input contains a minus sign, which no macaddr format includes. For comparison, an out-of-range two-digit-plus field is rejected as expected: SELECT '1ff:0:0:0:0:0'::macaddr; ERROR: invalid octet value in "macaddr" value: "1ff:0:0:0:0:0" Actual behavior: the overlong field is accepted and the stored octet is the input value modulo 2^32 (then masked to a byte), i.e. a different MAC address than the one entered, silently. Two observations from the source (src/backend/utils/adt/mac.c, macaddr_in): the first two sscanf formats use unbounded "%x" conversions, while the five condensed formats in the same function already use "%2x"; and C99 specifies that %x stores out-of-range values as the conversion modulo the target width rather than failing, so the subsequent a > 255 checks test the wrapped value. The newer macaddr8 type rejects these inputs (its input function does not use sscanf, per the discussion in 20170312193858.GW9812@tamriel.snowman.net). Happy to provide additional cases or a patch if useful. I found this while doing differential testing for pgrust.