Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xmsz4-0001xf-C8 for pgsql-bugs@arkaria.postgresql.org; Fri, 07 Nov 2014 23:30:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xmsz2-0003Dc-Ui for pgsql-bugs@arkaria.postgresql.org; Fri, 07 Nov 2014 23:30:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XmrWr-0001P9-IZ for pgsql-bugs@postgresql.org; Fri, 07 Nov 2014 21:57:13 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XmrWh-0004Vi-18 for pgsql-bugs@postgresql.org; Fri, 07 Nov 2014 21:57:12 +0000 MIME-Version: 1.0 Subject: BUG #11905: "Error: Wrong key or corrupt data" with pgp_sym_decrypt when bytea size is 2^x - 6 where x >=14 To: pgsql-bugs@postgresql.org From: connor.penhale@openlogic.com Date: Fri, 07 Nov 2014 21:56:38 +0000 Message-ID: <20141107215638.2527.18189@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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 can_decode.txt $ head -c 65530 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 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs