Re: BUG #17839: Heap-buffer overflow on float8_to_char with invalid template

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: thiagotnunes(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17839: Heap-buffer overflow on float8_to_char with invalid template
Date: 2023-03-14 22:49:05
Message-ID: 3011659.1678834145@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> Heap-buffer overflow on float8_to_char when format exceeds max double
> digits. I noticed this when running tests with memory sanitiser (msan).
> The following example triggers the failure (considering max double digits
> `DBL_DIG` is 15):
> float8_to_char(12345678901, "FM9999999999D999990")

Thanks for the report! For reasons that aren't entirely clear to me,
valgrind didn't whine about this until I added a few more zeroes to the
format string, like

SELECT to_char('12345678901'::float8, 'FM9999999999D9999900000000000000000');

Nonetheless, it did see the issue at that point. I'm inclined to fix
it by making the code that adjusts Np->last_relevant more paranoid,
as attached.

regards, tom lane

Attachment Content-Type Size
fix-wild-read-in-to_char.patch text/x-diff 2.1 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Thiago Nunes 2023-03-15 01:17:38 Re: BUG #17839: Heap-buffer overflow on float8_to_char with invalid template
Previous Message hubert depesz lubaczewski 2023-03-14 19:33:10 pg_read_server_files doesn't let me use pg_ls_dir() or pg_read_file?