BUG #15503: Bytea type column select failed when the length of the value is more than 512M

Started by PG Bug reporting formover 7 years ago3 messagesbugs
Jump to latest
#1PG Bug reporting form
noreply@postgresql.org

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

#2Michael Paquier
michael@paquier.xyz
In reply to: PG Bug reporting form (#1)
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

#3lichuancheng@highgo.com
lichuancheng@highgo.com
In reply to: PG Bug reporting form (#1)
Re: Re: BUG #15503: Bytea type column select failed when the length of the value is more than 512M

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