Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xllpw-0007gb-Q6 for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Nov 2014 21:40:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xllpw-0002gd-Au for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Nov 2014 21:40: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 1Xllpv-0002gX-PT for pgsql-bugs@postgresql.org; Tue, 04 Nov 2014 21:40:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xllpr-0000Q8-Q1 for pgsql-bugs@postgresql.org; Tue, 04 Nov 2014 21:40:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id sA4LeEDr018747; Tue, 4 Nov 2014 16:40:14 -0500 From: Tom Lane To: Saul Costa cc: pgsql-bugs@postgresql.org Subject: Re: PostgreSQL 9.3 Segfault in "hstore_to_json" function In-reply-to: References: Comments: In-reply-to Saul Costa message dated "Mon, 03 Nov 2014 13:23:58 -0800" Date: Tue, 04 Nov 2014 16:40:14 -0500 Message-ID: <18746.1415137214@sss.pgh.pa.us> X-Pg-Spam-Score: -2.5 (--) 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 Saul Costa writes: > Have found an occurrence of a segfault within "vanilla" PostgreSQL 9.3. > Fresh install, only change is having the hstore extension enabled. > Issue occurs when using the `hstore_to_json` function. Data was inserted > using SQLAlchemy but can be reproduced when using a COPY statement (see > "reproduce.sh"). Was not able to reproduce when running an INSERT statement > from the psql client (as it escaped the data differently and then did not > throw the segfault). If I copy / paste the data into a Python console and > print it it shows up correctly so I'm pretty sure this is not an encoding > issue. It looks like the problem is that 9.3's version of hstore_to_json() embeds an assumption that escape_json() can't increase the length of a string more than 2x. This is false for ASCII control characters, which get converted to "\uNNNN", so your test data leads to a buffer overrun that might or might not chance to stomp on anything critical. I see that's been fixed in 9.4 and HEAD, but it should've been back-patched to 9.3. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs