Обсуждение: array_dims function is poorly behaved

Поиск
Список
Период
Сортировка

array_dims function is poorly behaved

От
Marc Lavergne
Дата:
Simply use an array_dims() on any non-array type, the messages vary from:

SIS=# select array_dims(datdba) from pg_database;
pqReadData() -- backend closed the channel unexpectedly.
         This probably means the backend terminated abnormally
         before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.
!# ;
You are currently not connected to a database.
!# \q

to:

SIS=# select array_dims(datname) from pg_database;
ERROR:  MemoryContextAlloc: invalid request size 1702125936

Reproduces consistently on Linux (i386) 2.4.16 running 7.1.3.

Cheers,

Marc L.

--
01010101010101010101010101010101010101010101010101

Marc P. Lavergne [wk:407-648-6996]
Product Development
richLAVA Corporation

--

"Anyone who slaps a 'this page is best viewed with
Browser X' label on a Web page appears to be
yearning for the bad old days, before the Web,
when you had very little chance of reading a
document written on another computer, another word
processor, or another network."
-Tim Berners-Lee (Technology Review, July 1996)

01010101010101010101010101010101010101010101010101

Re: array_dims function is poorly behaved

От
Tom Lane
Дата:
Marc Lavergne <mlavergn@richlava.com> writes:
> Simply use an array_dims() on any non-array type,

There is not a lot to be done about that, I'm afraid, since our type
system doesn't have a concept of "any array type".  The only way we
have to declare array_dims() is as a function taking any type at all;
so it can't protect itself against inputs that aren't arrays.

We could add some code in array_dims to try to detect the case where
it's handed a non-array pass-by-reference type; but I don't see how
it can guard against a pass-by-value parameter, which will typically
equate to an invalid pointer :-(

A bulletproof solution would require adding the notion of "any array
type" to the type checking system.  That might be a good thing to do
someday, but I'm not planning to hold my breath while waiting...

            regards, tom lane