pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: lichuancheng@highgo.com
Subject: BUG #15503: Bytea type column select failed when the length of the value is more than 512M
Date: Wed, 14 Nov 2018 06:23:21 +0000
Message-ID: <15503-0ea185f3f6ad9b99@postgresql.org> (raw)

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



view thread (3+ messages)  latest in thread

Message-ID: <15503-0ea185f3f6ad9b99@postgresql.org>
Permalink:  ../15503-0ea185f3f6ad9b99@postgresql.org/
Also on:    postgresql.org/message-id/15503-0ea185f3f6ad9b99@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, lichuancheng@highgo.com
  Subject: Re: BUG #15503: Bytea type column select failed when the length of the value is more than 512M
  In-Reply-To: <15503-0ea185f3f6ad9b99@postgresql.org>
  References: <15503-0ea185f3f6ad9b99@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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