Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcMwJ-00085M-80 for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Mar 2023 08:56:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pcMwI-0002aL-4w for pgsql-bugs@arkaria.postgresql.org; Wed, 15 Mar 2023 08:56:54 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcGTc-0000Z7-89 for pgsql-bugs@lists.postgresql.org; Wed, 15 Mar 2023 02:02:52 +0000 Received: from mail-ua1-x934.google.com ([2607:f8b0:4864:20::934]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pcGTZ-00080m-Ro for pgsql-bugs@lists.postgresql.org; Wed, 15 Mar 2023 02:02:51 +0000 Received: by mail-ua1-x934.google.com with SMTP id 89so5003012uao.0 for ; Tue, 14 Mar 2023 19:02:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678845769; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Hf60txUEldQ7PHrnoCKd18WG++GCsQhp68kQM76PJ1U=; b=DHSX5mWXjOGDBBRNg4ndFuiz0h9ZdeBJFNP2lsyN5q0XFjZ09SKsYPYvjFlY0mrpHi /MCAejnr7REW+OcHp337GhlfbGzA38djjGf4U8tVRuCb9v5ekF8s08txCaQhVtkcUZ2C cPn19zkysFREz2pZMPX/6fuMyAbkIAJbmAcacJioCyA4JdZeJ+GU6iTCQzDN5jm/8c7K +o3OY1nft8KsJwpEGXbEqpP5FbC3uzmpfj/bwYpkudYYLtcwBOmD9x6/8Ktcc8rdIqG6 n1tdFlFnOThLf4vEA+1FBZfWb6hfQ3hZ2GhEx8OATamnF7OQ9AkzG+ir+CT33sojnDMX GZCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678845769; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Hf60txUEldQ7PHrnoCKd18WG++GCsQhp68kQM76PJ1U=; b=SIQhYEmqKQl5WFEIKFFveyvtnsSwbF3xAVz0/xx4b08JtnxqaqSmnCvuS8pe4Uw5mw 3GTM5Cmke2LNf4zUL8vjq58wdXcs8iRh0itcW5RHUkoKtStqE4fbFLOVvpOEYWoWFkb0 RUgYjBsj5altopN003c46Vx0WkeG1mjuNLWfGt1+1hllSzzjXp2VIACXCCM898pXG+y+ LetrbY1Ys7RvGuH3tFmz82ZJV2PPoEMVJ8RhpYVNPDVP/AL/ahRTHFySVElG9vRQxy5c jcuabrFo/DFBOlG12crBfoLexLQXuNPCq1yedLpOJj14QYy6vmGgv4mMP9cx+WzE1j4M 2V3w== X-Gm-Message-State: AO0yUKWE80ARw3cs2VbBkf7QblVjQ0YOeCq8obX0/9r41rRjCIPTrwi2 rE0Lbh7Chtl5b0cudkoNJ3hK/pFGTaMd5mral2ZBP1Hf X-Google-Smtp-Source: AK7set8OlMIBfEUwXBxF+R6+gFbodyzsV8RmFKTEZcIJGbHYTOsuHN3FKQrlyg/Ejl92cq+ZOk40dGi+s8m0GeuUjsM= X-Received: by 2002:ab0:4a1b:0:b0:68b:9eed:1c7c with SMTP id q27-20020ab04a1b000000b0068b9eed1c7cmr27017705uae.0.1678845769048; Tue, 14 Mar 2023 19:02:49 -0700 (PDT) MIME-Version: 1.0 References: <17839-aada50db24d7b0da@postgresql.org> <3011659.1678834145@sss.pgh.pa.us> <3076956.1678844746@sss.pgh.pa.us> In-Reply-To: <3076956.1678844746@sss.pgh.pa.us> From: Thiago Nunes Date: Wed, 15 Mar 2023 13:02:37 +1100 Message-ID: Subject: Re: BUG #17839: Heap-buffer overflow on float8_to_char with invalid template To: Tom Lane Cc: pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000b268af05f6e6bd1e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000b268af05f6e6bd1e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Got it, I thought that since we were filling the string with #s there, we should reposition the zero_end. I will wait for your patch then, thanks for looking into it! Cheers, On Wed, Mar 15, 2023 at 12:45=E2=80=AFPM Tom Lane wrote= : > Thiago Nunes writes: > > I think your solution deals with all the cases, but I would like to poi= nt > > out how I fixed it locally. I recalculated Num.zero_end after this line= ( > > > https://github.com/postgres/postgres/blob/REL_15_2/src/backend/utils/adt/= formatting.c#L6716 > > ): > > > ``` > > Num.zero_end =3D Num.pre + Num.post; > > ``` > > Hmm ... that seems a bit ad-hoc, because as far as I understand this > code, zero_end is supposed to track where is the last '0' format > character. That shouldn't change just because we decided that the > data value overflowed. > > regards, tom lane > --000000000000b268af05f6e6bd1e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Got it, I thought that since we were filling the string wi= th #s there, we should reposition the zero_end.

I will w= ait for your patch then, thanks for looking into it!

Cheers,

On Wed, Mar 15, 2023 at 12:45=E2=80=AFPM Tom Lane <tgl@sss.pgh.pa.us> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">Thiago Nunes <thiagotnunes@gmail.com= > writes:
> I think your solution deals with all the cases, but I would like to po= int
> out how I fixed it locally. I recalculated Num.zero_end after this lin= e (
> http= s://github.com/postgres/postgres/blob/REL_15_2/src/backend/utils/adt/format= ting.c#L6716
> ):

> ```
> Num.zero_end =3D Num.pre + Num.post;
> ```

Hmm ... that seems a bit ad-hoc, because as far as I understand this
code, zero_end is supposed to track where is the last '0' format character.=C2=A0 That shouldn't change just because we decided that the=
data value overflowed.

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane
--000000000000b268af05f6e6bd1e--