pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14599: Segmentation fault and database corruption with hstore
3+ messages / 3 participants
[nested] [flat]

* BUG #14599: Segmentation fault and database corruption with hstore
@ 2017-03-27 14:32 coladict@gmail.com
  2017-03-27 15:39 ` Re: BUG #14599: Segmentation fault and database corruption with hstore Andrew Gierth <andrew@tao11.riddles.org.uk>
  2017-03-27 15:52 ` Re: BUG #14599: Segmentation fault and database corruption with hstore David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 2 replies; 3+ messages in thread

From: coladict@gmail.com @ 2017-03-27 14:32 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      14599
Logged by:          Jordan Gigov
Email address:      coladict@gmail.com
PostgreSQL version: 9.5.6
Operating system:   Ubuntu 16.04
Description:        

I was testing a potential use of the hstore extension and data type when it
started crashing. The high-level API I rely on can only send this data type
as a string. It may not be limited to hstore, but that's the only thing I've
tested.

Steps to reproduce:
1. "CREATE EXTENSION hstore;" on a database.
2. Add an "hstore" field to any table.
3. "CREATE CAST (varchar AS hstore) WITHOUT FUNCTION AS ASSIGNMENT;". If we
skip step 4, everything works fine, but I was afraid it might fail with
longer strings, so I did that anyway.
4. "CREATE CAST (text AS hstore) WITHOUT FUNCTION AS ASSIGNMENT;". If I
skipped step 3 and only did 4, the cast was not detected with strings that
are too short.
5. This was done using Java + JDBC, but should work the same via
PREPARE/EXECUTE or any other driver's API:

    PreparedStatement ps = conn.prepareStatement("UPDATE the_table SET
hstore_field = ? WHERE id = ?");
    ps.setString(1, syntax_valid_data);
    ps.setLong(2, id);
    ps.execute();

From here on out, trying to fetch the data via SELECT will also result in
segfaults. Dropping the casts does not help.
The only solution was to drop the database and recreate from a backup.

I repeated the steps to be certain it's reproducible.


-- 
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] 3+ messages in thread

* Re: BUG #14599: Segmentation fault and database corruption with hstore
  2017-03-27 14:32 BUG #14599: Segmentation fault and database corruption with hstore coladict@gmail.com
@ 2017-03-27 15:39 ` Andrew Gierth <andrew@tao11.riddles.org.uk>
  1 sibling, 0 replies; 3+ messages in thread

From: Andrew Gierth @ 2017-03-27 15:39 UTC (permalink / raw)
  To: coladict@gmail.com; +Cc: pgsql-bugs

>>>>> "coladict" == coladict  <coladict@gmail.com> writes:

 coladict> 3. "CREATE CAST (varchar AS hstore) WITHOUT FUNCTION AS
 coladict> ASSIGNMENT;". If we skip step 4, everything works fine, but I
 coladict> was afraid it might fail with longer strings, so I did that
 coladict> anyway.

What on earth makes you think this is safe or useful? Creating a WITHOUT
FUNCTION cast opens a hole whereby you can feed values to the hstore
functions which are not actually valid hstores, so _of course_ it
crashes.  (There's a good reason why only superusers can create such
casts.)

Once you've stored such a value in a table, then subsequent accesses to
it will of course crash too.

-- 
Andrew (irc:RhodiumToad)


-- 
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] 3+ messages in thread

* Re: BUG #14599: Segmentation fault and database corruption with hstore
  2017-03-27 14:32 BUG #14599: Segmentation fault and database corruption with hstore coladict@gmail.com
@ 2017-03-27 15:52 ` David G. Johnston <david.g.johnston@gmail.com>
  1 sibling, 0 replies; 3+ messages in thread

From: David G. Johnston @ 2017-03-27 15:52 UTC (permalink / raw)
  To: Jordan Gigov <coladict@gmail.com>; +Cc: pgsql-bugs

On Mon, Mar 27, 2017 at 7:32 AM, <coladict@gmail.com> wrote:

> 3. "CREATE CAST (varchar AS hstore) WITHOUT FUNCTION AS ASSIGNMENT;". If we
> skip step 4, everything works fine, but I was afraid it might fail with
> longer strings, so I did that anyway.
> 4. "CREATE CAST (text AS hstore) WITHOUT FUNCTION AS ASSIGNMENT;". If I
> skipped step 3 and only did 4, the cast was not detected with strings that
> are too short.
> 5. This was done using Java + JDBC, but should work the same via
> PREPARE/EXECUTE or any other driver's API:
>
>     PreparedStatement ps = conn.prepareStatement("UPDATE the_table SET
> hstore_field = ? WHERE id = ?");
>     ps.setString(1, syntax_valid_data);
>     ps.setLong(2, id);
>     ps.execute();
>
>
​FWIW the differences between text and varchar observed here are an
implementation detail of the JDBC driver and not inherent to PostgreSQL.
Neither text nor varchar, unadorned, have length limitations and text is
always (I think...) the default target when an explicit type is not
specified.​

As Andrew said, its not a bug when you start doing legal but conceptually
invalid stuff.

Create a "string_to_hstore" function and do something like:

UPDATE the_table SET hstore_field = string_to_hstore(?::text) WHERE id =
?::integer;

Or just rely on the existing text-to-hstore cast...

UPDATE the_table SET hstore_field = string_to_hstore(?::text::hstore) WHERE
id = ?::integer;

David J.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2017-03-27 15:52 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-03-27 14:32 BUG #14599: Segmentation fault and database corruption with hstore coladict@gmail.com
2017-03-27 15:39 ` Andrew Gierth <andrew@tao11.riddles.org.uk>
2017-03-27 15:52 ` David G. Johnston <david.g.johnston@gmail.com>

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