From: Tom Lane <tgl@sss.pgh.pa.us>
To: Saul Costa <saul@mixrank.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: PostgreSQL 9.3 Segfault in "hstore_to_json" function
Date: Tue, 04 Nov 2014 16:40:14 -0500
Message-ID: <18746.1415137214@sss.pgh.pa.us> (raw)
In-Reply-To: <CA++cbU1o_r2wSNafkfBQjN7GZ1R8SQak2Ahztj4nP79tzLzkLw@mail.gmail.com>
References: <CA++cbU1o_r2wSNafkfBQjN7GZ1R8SQak2Ahztj4nP79tzLzkLw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Saul Costa <saul@mixrank.com> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, saul@mixrank.com
Subject: Re: PostgreSQL 9.3 Segfault in "hstore_to_json" function
In-Reply-To: <18746.1415137214@sss.pgh.pa.us>
References: <CA++cbU1o_r2wSNafkfBQjN7GZ1R8SQak2Ahztj4nP79tzLzkLw@mail.gmail.com> <18746.1415137214@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox