BUG #11905: "Error: Wrong key or corrupt data" with pgp_sym_decrypt when bytea size is 2^x - 6 where x >=14 - Mailing list pgsql-bugs

From connor.penhale@openlogic.com
Subject BUG #11905: "Error: Wrong key or corrupt data" with pgp_sym_decrypt when bytea size is 2^x - 6 where x >=14
Date
Msg-id 20141107215638.2527.18189@wrigleys.postgresql.org
Whole thread Raw
Responses Re: BUG #11905: "Error: Wrong key or corrupt data" with pgp_sym_decrypt when bytea size is 2^x - 6 where x >=14  (Jeff Janes <jeff.janes@gmail.com>)
List pgsql-bugs
The following bug has been logged on the website:

Bug reference:      11905
Logged by:          Connor Penhale
Email address:      connor.penhale@openlogic.com
PostgreSQL version: 9.3.1
Operating system:   OS X Yosemitie
Description:

Hello Postgres Community,

When I attempt to decrypt a file I successfully encrypted with a size of
65530, I get the “Error: Wrong key or corrupt data” message.

Here are the steps to reproduce in plain text:


$ head -c 65536 </dev/urandom > can_decode.txt
$ head -c 65530 </dev/urandom > can_not_decode.txt
$ psql

create or replace function bytea_import(p_path text, p_result out bytea)
language plpgsql as $$
declare
l_oid oid;
r record;
begin
p_result := '';
select lo_import(p_path) into l_oid;
for r in ( select data
from pg_largeobject
where loid = l_oid
order by pageno ) loop
p_result = p_result || r.data;
end loop;
perform lo_unlink(l_oid);
end;$$;


create table enc (file_name text PRIMARY KEY, blob bytea, file_size bigint)


insert into enc values ( 'can_decode.txt', (select
bytea_import(‘~/can_decode.txt')), 65536);


insert into enc values ( 'can_not_decode.txt', (select
bytea_import(‘~/can_not_decode.txt')), 65530);


select file_name,md5(blob),file_size from enc;
file_name | md5 | file_size
------------------------------+----------------------------------+-----------
can_decode.txt | a4a66bd8f16aab703857085e474a5873 | 65536
can_not_decode.txt | c04549e976852a555070c3a6ba9d64b4 | 65530


insert into enc values ( 'can_decode.txt enc', NULL , 65536);


insert into enc values ( 'can_not_decode.txt enc', NULL , 65530);


update enc set blob = (select pgp_sym_encrypt_bytea(blob, 'I AM THE
PASSWORD') from enc where file_name = 'can_decode.txt') where file_name =
'can_decode.txt enc';


update enc set blob = (select pgp_sym_encrypt_bytea(blob, 'I AM THE
PASSWORD') from enc where file_name = 'can_not_decode.txt') where file_name
= 'can_not_decode.txt enc';


insert into enc values ( 'can_decode.txt de-enc', NULL , 65536);


insert into enc values ( 'can_not_decode.txt de-enc', NULL , 65530);



update enc set blob = (select pgp_sym_decrypt_bytea(blob, 'I AM THE
PASSWORD') from enc where file_name = 'can_decode.txt enc') where file_name
= 'can_decode.txt de-enc';


update enc set blob = (select pgp_sym_decrypt_bytea(blob, 'I AM THE
PASSWORD') from enc where file_name = 'can_not_decode.txt enc') where
file_name = 'can_not_decode.txt de-enc';

At this point, I get the error.

I’ve been able to reproduce this on Postgres 9.1 and 9.3.

Please let me know if I can provide more information.

Thanks!
Connor

--
Connor Penhale | Open Source Solutions Architect
OpenLogic, a Rogue Wave Company
Accelerating Great Code
5500 Flatiron Parkway, Suite 200, Boulder, CO 80301
P 1 866-399-6736 | Toll Free

pgsql-bugs by date:

Previous
From: Rémi Zara
Date:
Subject: Build broken on mips
Next
From: Sergey Koposov
Date:
Subject: Re: BUG #11904: out of memory when scanning large number of partitions