[PATCH] Add error handling to byteaout. - Mailing list pgsql-hackers

From Andreas Seltenreich
Subject [PATCH] Add error handling to byteaout.
Date
Msg-id 87a8wif9wz.fsf@oort.credativ.de
Whole thread Raw
Responses Re: [PATCH] Add error handling to byteaout.  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,

when dealing with bytea values that are below the 1GB limit, but too
large to be escaped, the error messages emitted are not very helpful for
users.  Especially if they appear in an unrelated context such as during
pg_dump.  I've attached a patch that adds ereport()ing that would have
prevented some confusion.

Example:

,----[ master ]
| ase=# select mkbytea(29);
| ERROR:  invalid memory alloc request size 1073741827
| ase=# set bytea_output to escape;
| ase=# select mkbytea(29);
| ERROR:  invalid memory alloc request size 18446744071562067969
`----

The scary one is due to an integer overflow the attached patch also
fixes.  I don't see any security implications though as it's only the
sign bit that is affected.

,----[ with patch applied ]
| ase=# set bytea_output to 'escape';
| ase=# select mkbytea(29);
| ERROR:  escaped bytea value would be too big
| DETAIL:  Value would require 2147483649 bytes.
| HINT:  Use a different bytea_output setting or binary methods such as COPY BINARY.
`----

regards,
Andreas

create function mkbytea(power int, part bytea default '\x00')      returns bytea as      $$select case when power>0
thenmkbytea(power-1,part||part) else part end;$$      language sql;
 


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: nested loop semijoin estimates
Next
From: Andres Freund
Date:
Subject: Re: checkpointer continuous flushing