`array_position...()` causes SIGSEGV

Started by Junseok Yangover 9 years ago4 messageshackers
Jump to latest
#1Junseok Yang
jsyang@bitnine.net

Hello hackers,

I met SIGSEGV when using `array_position()` with record type
arguments, so I've written a patch which corrects this problem. It
seems that `array_position...()` sets wrong memory context for the
cached function (in this case `record_eq()`) which is used to find a
matching element.

The problem is reproducable with the following query.

SELECT array_position(ids, (1, 1))
FROM (VALUES (ARRAY[(0, 0)]), (ARRAY[(1, 1)])) AS _(ids);

Attachments:

0001-Fix-memory-context-bugs-in-array_position.patchtext/x-patch; charset=US-ASCII; name=0001-Fix-memory-context-bugs-in-array_position.patchDownload+4-3
#2Michael Paquier
michael@paquier.xyz
In reply to: Junseok Yang (#1)
Re: `array_position...()` causes SIGSEGV

On Fri, Dec 9, 2016 at 3:14 PM, Junseok Yang <jsyang@bitnine.net> wrote:

I met SIGSEGV when using `array_position()` with record type
arguments, so I've written a patch which corrects this problem. It
seems that `array_position...()` sets wrong memory context for the
cached function (in this case `record_eq()`) which is used to find a
matching element.

The problem is reproducable with the following query.

SELECT array_position(ids, (1, 1))
FROM (VALUES (ARRAY[(0, 0)]), (ARRAY[(1, 1)])) AS _(ids);

Good catch. That's present since 13dbc7a8 and the introduction of
array_offset(), or array_position() on HEAD, so the patch should be
applied down to 9.5.
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Michael Paquier (#2)
Re: `array_position...()` causes SIGSEGV

Michael Paquier wrote:

On Fri, Dec 9, 2016 at 3:14 PM, Junseok Yang <jsyang@bitnine.net> wrote:

I met SIGSEGV when using `array_position()` with record type
arguments, so I've written a patch which corrects this problem. It
seems that `array_position...()` sets wrong memory context for the
cached function (in this case `record_eq()`) which is used to find a
matching element.

The problem is reproducable with the following query.

SELECT array_position(ids, (1, 1))
FROM (VALUES (ARRAY[(0, 0)]), (ARRAY[(1, 1)])) AS _(ids);

Good catch. That's present since 13dbc7a8 and the introduction of
array_offset(), or array_position() on HEAD, so the patch should be
applied down to 9.5.

Thanks for CC'ing me. Looking now.

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Junseok Yang (#1)
Re: `array_position...()` causes SIGSEGV

Junseok Yang wrote:

Hello hackers,

I met SIGSEGV when using `array_position()` with record type
arguments, so I've written a patch which corrects this problem. It
seems that `array_position...()` sets wrong memory context for the
cached function (in this case `record_eq()`) which is used to find a
matching element.

Looks correct to me, so pushed to all affected branches.

The problem is reproducable with the following query.

SELECT array_position(ids, (1, 1))
FROM (VALUES (ARRAY[(0, 0)]), (ARRAY[(1, 1)])) AS _(ids);

I used this as a new regression test.

Thanks for the report and patch!

--
�lvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers