invalid memory alloc request size with extension url_decode

Поиск
Список
Период
Сортировка
От Tobias Florek
Тема invalid memory alloc request size with extension url_decode
Дата
Msg-id 53FF3C01.3010406@ibotty.net
обсуждение исходный текст
Ответы Re: invalid memory alloc request size with extension url_decode  (Tobias Florek <postgres@ibotty.net>)
Re: invalid memory alloc request size with extension url_decode  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-novice
hi all,

using the extension url_encode (not on pgxn) does not work in postgresql
9.3 (and 9.4). (i assume it works in earlier versions, but i have not
tested that.)


the testcase is the following.

     create table t (id serial primary key, t1 text not null, t2 text);
     insert into t (t1) values ('test');
     update t set t2 = url_encode(t1);

it fails with

     Error: invalid memory alloc request size 1452021511


for my untrained eye, the code [2] looks reasonable. it does use the
following idiom though.

static text *
encode(text *in_text, ...)
{
   ...
   real_len = 0;
   len = VARSIZE(in_text) - VARHDRSZ;
   result = (text *) palloc(3 * len + VARHDRSZ);
   write_ptr = VARDATA(result);

   ...

   SET_VARSIZE(result, real_len + VARHDRSZ);
   return result;
}

is that safe for "text" data type? how should it be replaced if not?

[1] https://github.com/okbob/url_encode
[2] https://github.com/okbob/url_encode/blob/master/src/url_encode.c

thank you in advance,
  tobias florek


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

Предыдущее
От: Marc Richter
Дата:
Сообщение: Re: PG 9.1 much slower than 8.2 ?
Следующее
От: Tobias Florek
Дата:
Сообщение: Re: invalid memory alloc request size with extension url_decode