Re: query_int wrongly parses zero-padded input

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marko Grujic <marko(dot)grujic(at)enterprisedb(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: query_int wrongly parses zero-padded input
Date: 2026-10-17 22:51:44
Message-ID: 188703.1792277504@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Marko Grujic <marko(dot)grujic(at)enterprisedb(dot)com> writes:
> I'm reporting a minor, long-standing, edge case in intarray here.
> Namely, when parsing a query_int, the strtol base is set to 0, which forces
> the base auto-detection mode.
> Consequently, when a zero-padded integer input is provided, the number is
> interpreted as an octal value, which in turn leads to wrong int-query results

Hmm ... of course, "wrong" is in the eye of the beholder. There are a
large number of places where we intentionally use base 0, mostly in
service of allowing hex input. I tend to agree with you that this
case wasn't intentional, since the preceding parsing logic only
accepts a sign and 0-9, not "x" or hex digits. Still, we should
consider whether the right answer is to fix that logic to allow
hex input. A (weak) argument for going that way is we'd stay
bug-compatible with the existing behavior for octal input.

I checked around and couldn't find any other places where it seemed
like base zero was being specified unintentionally: in particular
we intentionally use it for integer GUCs, and the parsing logic
is such that you can put in 0x-whatever in all the related places.

On the whole I agree with you that this is a bug and it should use
base 10, but we should wait to see if anyone disagrees.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2026-10-18 00:09:54 Re: pgstat: allow a stats kind to use its own dedicated dsa/dshash
Previous Message Manu 2026-10-17 20:39:00 Re: [PATCH] Extensible ReadyForQuery wire protocol message and C hook, for connection pools and WAIT FOR LSN