| From: | wangyang25(at)otcaix(dot)iscas(dot)ac(dot)cn |
|---|---|
| To: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | macaddr8 accepts one trailing character after a complete address |
| Date: | 2026-11-23 11:20:16 |
| Message-ID: | 179543281614.3780281.320089935544088532@otcaix.iscas.ac.cn |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
macaddr8 silently discards one trailing character after a complete address
Summary
PostgreSQL 19.0 accepts a complete macaddr8 address followed by one extra non-whitespace character, discards that character, and returns the address parsed without it. For example, the malformed input 08:00:2b:01:02:03f is accepted as 08:00:2b:ff:fe:01:02:03.
The network address type documentation (https://www.postgresql.org/docs/19/datatype-net-types.html#DATATYPE-MACADDR8) describes macaddr8 input as pairs of hexadecimal digits, with 12 or 16 digits; leading and trailing whitespace is ignored.
Reproduction
Run this query in a clean psql -X session:
SELECT quote_literal(value) AS input,
pg_input_is_valid(value, 'macaddr8') AS accepted,
CASE WHEN pg_input_is_valid(value, 'macaddr8')
THEN value::macaddr8::text
END AS parsed
FROM (VALUES ('08:00:2b:01:02:03'),
('08:00:2b:01:02:03f'),
('08:00:2b:01:02:03z'),
('08:00:2b:01:02:03 '),
('08:00:2b:01:02:03:04:05'),
('08:00:2b:01:02:03:04:05z')) AS input(value);
On PostgreSQL 19.0, pg_input_is_valid returns true for all six values. The f and z suffixes are discarded; the whitespace control is also accepted. The six-byte address is converted to EUI-64 by inserting ff:fe, and the eight-byte control is preserved:
input | accepted | parsed
------------------------------+----------+-------------------------
'08:00:2b:01:02:03' | t | 08:00:2b:ff:fe:01:02:03
'08:00:2b:01:02:03f' | t | 08:00:2b:ff:fe:01:02:03
'08:00:2b:01:02:03z' | t | 08:00:2b:ff:fe:01:02:03
'08:00:2b:01:02:03 ' | t | 08:00:2b:ff:fe:01:02:03
'08:00:2b:01:02:03:04:05' | t | 08:00:2b:01:02:03:04:05
'08:00:2b:01:02:03:04:05z' | t | 08:00:2b:01:02:03:04:05
For example:
SELECT '08:00:2b:01:02:03f'::macaddr8;
-- 08:00:2b:ff:fe:01:02:03
The same behavior was reproduced in two independent PostgreSQL 19.0 sessions and in the previously tested PostgreSQL 18.6 installation.
Expected behavior
The values ending in f or z should be rejected as invalid input: the extra character is neither part of a complete hexadecimal pair nor permitted trailing whitespace. The complete six-byte and eight-byte controls should remain accepted.
Source observation
In PostgreSQL 19.0, macaddr8_in() (https://github.com/postgres/postgres/blob/5c839a2a08b9b87a349be97371fac6c5a2873b10/src/backend/utils/adt/mac8.c#L119-L120) states that digits must come in pairs and enters its parsing loop only while at least two characters remain. After six or eight bytes, a lone remaining character therefore bypasses the loop; the post-loop length check accepts the value without checking that character. Existing macaddr8 regression cases (https://github.com/postgres/postgres/blob/5c839a2a08b9b87a349be97371fac6c5a2873b10/src/test/regress/sql/macaddr8.sql#L14-L23) also classify trailing garbage after a complete address as invalid, though they do not include the one-character boundary case.
Related report
BUG #19583 (https://www.postgresql.org/message-id/19583-ca7c85d40164f18b@postgresql.org) concerns overlong octet fields in the separate macaddr_in() parser. Its discussion notes that macaddr8_in() uses a hand-written parser; this report concerns that parser's handling of a single unconsumed character after a complete address.
Tested environment
- PostgreSQL 19.0 server and psql client (REL_19_0, commit 5c839a2a08b9b87a349be97371fac6c5a2873b10); PostgreSQL 18.6 also reproduced the behavior.
- Ubuntu 24.04, Linux kernel 7.0.0-38-generic, x86-64, GCC 13.3.0. Build options: --without-readline --without-zlib --without-icu --without-llvm.
- A fresh cluster was initialized with initdb --no-locale -E UTF8 --auth-local=trust --auth-host=reject and listened on a local socket only. Startup settings were listen_addresses='', port=55491, max_connections=20, and shared_buffers=32MB; the socket directory was local to the test environment. No other configuration was changed.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nitin Motiani | 2026-11-23 11:40:04 | Re: BUG #19931: postgres_fdw: FOR UPDATE over a pushed-down join ignores a pseudoconstant qual |
| Previous Message | Shlok Kyal | 2026-11-23 10:00:47 | Re: Logical replication commits duplicates in DEFERRABLE unique indexes |