pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15503: Bytea type column select failed when the length of the value is more than 512M
3+ messages / 3 participants
[nested] [flat]

* BUG #15503: Bytea type column select failed when the length of the value is more than 512M
@ 2018-11-14 06:23  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2018-11-14 06:23 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: lichuancheng@highgo.com

The following bug has been logged on the website:

Bug reference:      15503
Logged by:          li chuancheng
Email address:      lichuancheng@highgo.com
PostgreSQL version: 10.4
Operating system:   centos7
Description:        

Question1:
Bytea accecp almost 1G data length, but we select failed when data is more
than 512M-5byte with HEX type output
###################Here is the sample.###################
postgres=# insert into t1 values(1,pg_read_binary_file('testfile_512M'));
INSERT 0 1
postgres=# select j from t1 where i = 1;
2018-11-14 13:39:43.251 CST [19366] ERROR:  invalid memory alloc request
size 1073741827
2018-11-14 13:39:43.251 CST [19366] STATEMENT:  select j from t1 where i =
1;
ERROR:  invalid memory alloc request size 1073741827
postgres=#
######################################################
It is due to the length expand when trans to HEX.

Question2:
When i investigation question1 i find some problem of code.
Problem1:
------------------
Datum
byteaout(PG_FUNCTION_ARGS)
{
	 ...
	 else if (bytea_output == BYTEA_OUTPUT_ESCAPE)
	 {
	      ...
              int			len;
	      ...
	     rp = result = (char *) palloc(len);
              ...
         }
 }
------------------
The type of 'len' shoule be int64. Because i have find a bug below when
select with ESCAPE and 1G length of bytea value.
#########################################################
postgres=# insert into t1 values(3,pg_read_binary_file('testfile_1G'));
INSERT 0 1
postgres=# select j from t1 where i = 3;
2018-11-14 14:08:55.688 CST [20832] ERROR:  invalid memory alloc request
size 18446744072506499617
2018-11-14 14:08:55.688 CST [20832] STATEMENT:  select j from t1 where i =
3;
ERROR:  invalid memory alloc request size 18446744072506499617
postgres=# 
#########################################################

Question3:
Here is a bug of function get_bit()
#########################################################
postgres=# select get_bit(j,10) from t1 where i = 1;
2018-11-14 14:15:33.158 CST [20832] ERROR:  index 10 out of valid range,
0..-1
2018-11-14 14:15:33.158 CST [20832] STATEMENT:  select get_bit(j,10) from t1
where i = 1;
ERROR:  index 10 out of valid range, 0..-1
postgres=# select get_bit(j,10) from t1 where i = 3;
2018-11-14 14:15:38.212 CST [20832] ERROR:  index 10 out of valid range,
0..-8388609
2018-11-14 14:15:38.212 CST [20832] STATEMENT:  select get_bit(j,10) from t1
where i = 3;
ERROR:  index 10 out of valid range, 0..-8388609
postgres=#
#########################################################
It is similar to question2. In function byteaGetByte, the type of 'len'
should be int64.


is it a bug?
thanks, 
best regards. 
lchch



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #15503: Bytea type column select failed when the length of the value is more than 512M
@ 2018-11-14 07:57  Michael Paquier <michael@paquier.xyz>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Michael Paquier @ 2018-11-14 07:57 UTC (permalink / raw)
  To: lichuancheng@highgo.com; pgsql-bugs@lists.postgresql.org

On Wed, Nov 14, 2018 at 06:23:21AM +0000, PG Bug reporting form wrote:
> is it a bug?

Nope.  palloc() is able to allocate up to 1GB.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Re: BUG #15503: Bytea type column select failed when the length of the value is more than 512M
@ 2018-11-14 08:04  lichuancheng@highgo.com <lichuancheng@highgo.com>
  parent: Michael Paquier <michael@paquier.xyz>
  0 siblings, 0 replies; 3+ messages in thread

From: lichuancheng@highgo.com @ 2018-11-14 08:04 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>

>Nope.  palloc() is able to allocate up to 1GB.

The size of bytea is 512M,but in byteaout() function, it expend to more than 1G.
######
rp = result = palloc(VARSIZE_ANY_EXHDR(vlena) * 2 + 2 + 1);
######

--
lchch
 
From: Michael Paquier
Date: 2018-11-14 15:57
To: lichuancheng@highgo.com; pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15503: Bytea type column select failed when the length of the value is more than 512M
On Wed, Nov 14, 2018 at 06:23:21AM +0000, PG Bug reporting form wrote:
> is it a bug?
 
Nope.  palloc() is able to allocate up to 1GB.
--
Michael


^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2018-11-14 08:04 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-11-14 06:23 BUG #15503: Bytea type column select failed when the length of the value is more than 512M PG Bug reporting form <noreply@postgresql.org>
2018-11-14 07:57 ` Michael Paquier <michael@paquier.xyz>
2018-11-14 08:04   ` lichuancheng@highgo.com <lichuancheng@highgo.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox