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

From: connor(dot)penhale(at)openlogic(dot)com
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #11905: "Error: Wrong key or corrupt data" with pgp_sym_decrypt when bytea size is 2^x - 6 where x >=14
Date: 2014-11-07 21:56:38
Message-ID: 20141107215638.2527.18189@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 11905
Logged by: Connor Penhale
Email address: connor(dot)penhale(at)openlogic(dot)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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Rémi Zara 2014-11-07 22:25:50 Build broken on mips
Previous Message Tom Lane 2014-11-07 21:33:38 Re: BUG #11904: out of memory when scanning large number of partitions