Re: Bug: Reading from single byte character column type may cause out of bounds memory reads.

Поиск
Список
Период
Сортировка
От Aleksander Alekseev
Тема Re: Bug: Reading from single byte character column type may cause out of bounds memory reads.
Дата
Msg-id CAJ7c6TNguAKGcYxk=SHGvGAGfdrx_2DP5bvtDNu+eQ+3kDbt7w@mail.gmail.com
обсуждение исходный текст
Ответ на Bug: Reading from single byte character column type may cause out of bounds memory reads.  (Spyridon Dimitrios Agathos <spyridon.dimitrios.agathos@gmail.com>)
Ответы Re: Bug: Reading from single byte character column type may cause out of bounds memory reads.  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Bug: Reading from single byte character column type may cause out of bounds memory reads.  (Isaac Morland <isaac.morland@gmail.com>)
Re: Bug: Reading from single byte character column type may cause out of bounds memory reads.  (Nikolay Shaplov <dhyan@nataraj.su>)
Список pgsql-hackers
Hi Spyridon,

> The column "single_byte_col" is supposed to store only 1 byte. Nevertheless, the INSERT command implicitly casts the
'🀆'text into "char". This means that only the first byte of '🀆' ends up stored in the column. 
> gdb reports that "pg_mblen(p) = 4" (line 1046), which is expected since the pg_mblen('🀆') is indeed 4. Later at line
1050,the memcpy will copy 4 bytes instead of 1, hence an out of bounds memory read happens for pointer 's', which
effectivelycopies random bytes. 

Many thanks for reporting this!

> - OS: Ubuntu 20.04
> - PSQL version 14.4

I can confirm the bug exists in the `master` branch as well and
doesn't depend on the platform.

Although the bug is easy to fix for this particular case (see the
patch) I'm not sure if this solution is general enough. E.g. is there
something that generally prevents pg_mblen() from doing out of bound
reading in cases similar to this one? Should we prevent such an INSERT
from happening instead?

--
Best regards,
Aleksander Alekseev

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Alexander Korotkov
Дата:
Сообщение: Re: Building PostgreSQL in external directory is broken?
Следующее
От: "Jonathan S. Katz"
Дата:
Сообщение: Re: PG15 beta1 sort performance regression due to Generation context change