pg.ddx.io pgsql-bugs@postgresql.org mailing list archivehelp / color / mirror / Atom feed
PostgreSQL 9.3 Segfault in "hstore_to_json" function 2+ messages / 2 participants [nested] [flat]
* PostgreSQL 9.3 Segfault in "hstore_to_json" function @ 2014-11-03 21:23 Saul Costa <saul@mixrank.com> 0 siblings, 1 reply; 2+ messages in thread From: Saul Costa @ 2014-11-03 21:23 UTC (permalink / raw) To: pgsql-bugs Good afternoon! 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. There are two strange things about this bug. First, it only seems to happen when `hstore_to_json` is called twice during the same session (compare the last two test cases in the included "reproduce.sh" script). Second, it only occurs when there is another key / value pair present in the hstore column, and this key must be of a certain length to trigger the issue (from what I can tell, 8 characters). The second test case illustrates that it works with shorter length keys. To reproduce, adjust the `USER` and `DATABASE` variables in "reproduce.sh" to account for your local username / database. I needed to do it like this due to the aforementioned issues with reproducing it using an INSERT statement. Included files: "reproduce.sh" - Shell script for reproducing the issue. Runs through multiple test cases to illustrate different scenarios that work before providing a breaking example. "log_output.txt" - Relevant log lines when running with DEBUG5 logging level (note line 11) Version / encoding information is contained in "reproduce.sh" Cheers! -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs Attachments:reproduce.sh (application/x-sh, 4.7K) download ^ permalink raw reply [nested|flat] 2+ messages in threadlog_output.txt (text/plain, 2.6K) download
2014-11-03 13:05:51 PST LOG: statement: CREATE EXTENSION IF NOT EXISTS hstore; DROP TABLE IF EXISTS hstore_to_json_test; CREATE TABLE hstore_to_json_test (properties hstore); 2014-11-03 13:05:51 PST LOG: statement: COPY hstore_to_json_test (properties) FROM STDIN 2014-11-03 13:05:51 PST LOG: statement: SELECT hstore_to_json(properties) FROM hstore_to_json_test; SELECT hstore_to_json(properties) FROM hstore_to_json_test; 2014-11-03 13:05:52 PST LOG: statement: TRUNCATE hstore_to_json_test; 2014-11-03 13:05:52 PST LOG: statement: COPY hstore_to_json_test (properties) FROM STDIN 2014-11-03 13:05:53 PST LOG: statement: SELECT hstore_to_json(properties) FROM hstore_to_json_test; SELECT hstore_to_json(properties) FROM hstore_to_json_test; 2014-11-03 13:05:53 PST LOG: statement: TRUNCATE hstore_to_json_test; 2014-11-03 13:05:53 PST LOG: statement: COPY hstore_to_json_test (properties) FROM STDIN 2014-11-03 13:05:53 PST LOG: statement: SELECT hstore_to_json(properties) FROM hstore_to_json_test; 2014-11-03 13:05:54 PST LOG: statement: SELECT hstore_to_json(properties) FROM hstore_to_json_test; SELECT hstore_to_json(properties) FROM hstore_to_json_test; 2014-11-03 13:05:54 PST LOG: server process (PID 20528) was terminated by signal 11: Segmentation fault 2014-11-03 13:05:54 PST DETAIL: Failed process was running: SELECT hstore_to_json(properties) FROM hstore_to_json_test; SELECT hstore_to_json(properties) FROM hstore_to_json_test; 2014-11-03 13:05:54 PST LOG: terminating any other active server processes 2014-11-03 13:05:54 PST WARNING: terminating connection because of crash of another server process 2014-11-03 13:05:54 PST DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory. 2014-11-03 13:05:54 PST HINT: In a moment you should be able to reconnect to the database and repeat your command. 2014-11-03 13:05:54 PST LOG: all server processes terminated; reinitializing 2014-11-03 13:05:54 PST LOG: database system was interrupted; last known up at 2014-11-03 13:00:42 PST 2014-11-03 13:05:54 PST LOG: database system was not properly shut down; automatic recovery in progress 2014-11-03 13:05:54 PST LOG: redo starts at 0/1B24C88 2014-11-03 13:05:54 PST LOG: record with zero length at 0/1B44D00 2014-11-03 13:05:54 PST LOG: redo done at 0/1B44CD0 2014-11-03 13:05:54 PST LOG: last completed transaction was at log time 2014-11-03 13:05:53.717001-08 2014-11-03 13:05:54 PST LOG: database system is ready to accept connections 2014-11-03 13:05:54 PST LOG: autovacuum launcher started
* Re: PostgreSQL 9.3 Segfault in "hstore_to_json" function @ 2014-11-04 21:40 Tom Lane <tgl@sss.pgh.pa.us> parent: Saul Costa <saul@mixrank.com> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2014-11-04 21:40 UTC (permalink / raw) To: Saul Costa <saul@mixrank.com>; +Cc: pgsql-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 ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2014-11-04 21:40 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2014-11-03 21:23 PostgreSQL 9.3 Segfault in "hstore_to_json" function Saul Costa <saul@mixrank.com> 2014-11-04 21:40 ` Tom Lane <tgl@sss.pgh.pa.us>
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