Re: Re[2]: BUG #17561: Server crashes on executing row() with very long argument list

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Егор Чиндяскин <kyzevan23(at)mail(dot)ru>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: Re[2]: BUG #17561: Server crashes on executing row() with very long argument list
Date: 2022-08-01 10:51:26
Message-ID: CAMbWs4_hj8PFeRWkzndqf=VYj1E3dAKivVxQpdBU6n4DfpgTNw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Aug 1, 2022 at 6:33 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:

>
> On Mon, Aug 1, 2022 at 6:03 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
>
>>
>> On Mon, Aug 1, 2022 at 3:17 PM Егор Чиндяскин <kyzevan23(at)mail(dot)ru> wrote:
>>
>>> Thank you, Tom! The fix works for that case, but there is another one.
>>> I got server crashed while executing the following script:
>>>
>>> (echo "SELECT * FROM json_to_record('{\"0\":0
>>> ";for((i=1;i<100001;i++));do echo ",\"$i\":$i";done; echo "}') as x("; echo
>>> "\"0\" int";for((i=1;i<100001;i++));do echo ",\"$i\" int";done;echo ")") |
>>> psql
>>>
>>
>> Thanks for the report! This is another place that we construct a tupdesc
>> with more than MaxAttrNumber attributes, via RangeFunctions this time.
>>
>> Regarding the fix, how about we check the length of coldeflist against
>> MaxTupleAttributeNumber in transformRangeFunction()?
>>
>
> I mean something like this:
>
> diff --git a/src/backend/parser/parse_clause.c
> b/src/backend/parser/parse_clause.c
> index 5a18107e79..a74a07667d 100644
> --- a/src/backend/parser/parse_clause.c
> +++ b/src/backend/parser/parse_clause.c
> @@ -629,6 +629,15 @@ transformRangeFunction(ParseState *pstate,
> RangeFunction *r)
> */
> if (r->coldeflist)
> {
> + /* Disallow more columns than will fit in a tuple */
> + if (list_length(r->coldeflist) > MaxTupleAttributeNumber)
> + ereport(ERROR,
> + (errcode(ERRCODE_TOO_MANY_COLUMNS),
> + errmsg("Function returning RECORD
> can have at most %d entries",
> +
> MaxTupleAttributeNumber),
> + parser_errposition(pstate,
> +
> exprLocation((Node *) r->coldeflist))));
> +
> if (list_length(funcexprs) != 1)
> {
> if (r->is_rowsfrom)
>
>
Just noticed that CheckAttributeNamesTypes will check on column count
against MaxHeapAttributeNumber. Maybe we should use this as the limit?

Thanks
Richard

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2022-08-01 14:09:16 Re: BUG #17563: exception " Segmentation fault" occured when i executed 'reindex index concurrently' in pg12.0
Previous Message Richard Guo 2022-08-01 10:33:31 Re: Re[2]: BUG #17561: Server crashes on executing row() with very long argument list