Skip to content

wrong type of text crashes the server #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rmesser opened this issue Jun 16, 2016 · 2 comments
Open

wrong type of text crashes the server #22

rmesser opened this issue Jun 16, 2016 · 2 comments

Comments

@rmesser
Copy link

rmesser commented Jun 16, 2016

I have a function that crashes my postgres 9.5 server. Here is the PL/R function:

CREATE OR REPLACE FUNCTION test_svg () RETURNS text AS
$$
library("svglite")
library("ggplot2")

# set up to output svg to a string
s = svgstring()

# create the plot, as an example
ggplot(mapping = aes(cars$speed)) + geom_density()

# NOTE: this works:
# plot(density(cars$speed))

# fetch the string
svg = s()

# turn off output to the string
dev.off()

return(svg)
$$
LANGUAGE 'plr' IMMUTABLE;

When I run this, the whole server crashes, and all connections are dropped. Here is the main part of the error message in my postgresql logs:

Error: CHAR() can only be applied to a 'CHARSXP', not a 'pairlist'
*** stack smashing detected ***: postgres: postgres c7_70 [local] SELECT terminated
======= Backtrace: =========
/lib64/libc.so.6(__fortify_fail+0x37)[0x7fc78c616b37]
/lib64/libc.so.6(__fortify_fail+0x0)[0x7fc78c616b00]
/usr/lib64/R/lib/libR.so(+0x1412d1)[0x7fc73f2182d1]

Curiously, if I simply remove the return(svg) statement and instead do return("foo"), it works fine (but of course I don't get the output I want). So somehow the process of returning the svg string and coercing it to the postgresql text causes a hard crash. It is also odd to me that the regular old "plot" works just fine. Maybe that means this is a bug in svglite or ggplot2, but it would be nice if PL/R prevented server crashes as much as possible. Maybe it is something about the svg generated by ggplot2 that causes the problem.

As a side note, I am new to PL/R but find it confusing how returning text often fails. For example, if I have two strings and concatenate them, no dice. That is, this doesn't work:

CREATE OR REPLACE FUNCTION R_test_cat () RETURNS text AS $$ return(cat("foo","bar")) $$ language 'plr';

When running this I get nothing, whereas a simple return("foo bar") works just fine. If there is something I am doing wrong in either of these cases please advise. Thanks, and appreciate the efforts on PL/R, it is a very useful module.

@kmatt
Copy link

kmatt commented Jun 17, 2016

Might be good to submit this to [email protected] in case this is something that should be trapped in the engine, preventing a DB crash.

On Jun 16, 2016, at 7:04 PM, Robert Messer [email protected] wrote:

I have a function that crashes my postgres 9.5 server. Here is the PL/R function:

CREATE OR REPLACE FUNCTION test_svg () RETURNS text AS
$$
library("svglite")
library("ggplot2")

set up to output svg to a string

s = svgstring()

create the plot, as an example

ggplot(mapping = aes(cars$speed)) + geom_density()

NOTE: this works:

plot(density(cars$speed))

fetch the string

svg = s()

turn off output to the string

dev.off()

return(svg)
$$
LANGUAGE 'plr' IMMUTABLE;
When I run this, the whole server crashes, and all connection are dropped. Here is the main part of the error message in my postgresql logs:

Error: CHAR() can only be applied to a 'CHARSXP', not a 'pairlist'
*** stack smashing detected ***: postgres: postgres c7_70 [local] SELECT terminated
======= Backtrace: =========
/lib64/libc.so.6(__fortify_fail+0x37)[0x7fc78c616b37]
/lib64/libc.so.6(__fortify_fail+0x0)[0x7fc78c616b00]
/usr/lib64/R/lib/libR.so(+0x1412d1)[0x7fc73f2182d1]

Curiously, if I simply remove the return statement and do return("foo"), it works fine (but of course I don't get the output I want. So somehow the process of returning the svg and coercing to the postgresql text causes a hard crash. It is also odd to me that the regular old "plot" works just fine. Maybe that means this is a bug in svglite or ggplot2, but it would be nice if PL/R prevented against server crashes as much as possible. Maybe it is something about the svg generated by ggplot2 that causes the problem.

As a side note, I am new to PL/R but find it confusing how returning text often fails. For example, if I have two string and concatenate them, no dice. That is, this doesn't work:

CREATE OR REPLACE FUNCTION R_test_cat () RETURNS text AS $$ return(cat("foo","bar")) $$ language 'plr';
When running this I get nothing, whereas a simple return("foo bar") works just fine. If there is something I am going wrong in either of these cases please advise. Thanks, and appreciate the efforts on PL/R, it is a very useful modules.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

@davecramer
Copy link
Collaborator

Unfortunately I don't think the backend can trap these things... Will look
at this shortly. Thanks for the testcase

Dave Cramer

On 16 June 2016 at 21:32, MattK [email protected] wrote:

Might be good to submit this to [email protected] in case this is
something that should be trapped in the engine, preventing a DB crash.

On Jun 16, 2016, at 7:04 PM, Robert Messer [email protected]
wrote:

I have a function that crashes my postgres 9.5 server. Here is the PL/R
function:

CREATE OR REPLACE FUNCTION test_svg () RETURNS text AS
$$
library("svglite")
library("ggplot2")

set up to output svg to a string

s = svgstring()

create the plot, as an example

ggplot(mapping = aes(cars$speed)) + geom_density()

NOTE: this works:

plot(density(cars$speed))

fetch the string

svg = s()

turn off output to the string

dev.off()

return(svg)
$$
LANGUAGE 'plr' IMMUTABLE;
When I run this, the whole server crashes, and all connection are
dropped. Here is the main part of the error message in my postgresql logs:

Error: CHAR() can only be applied to a 'CHARSXP', not a 'pairlist'
*** stack smashing detected ***: postgres: postgres c7_70 [local] SELECT
terminated
======= Backtrace: =========
/lib64/libc.so.6(__fortify_fail+0x37)[0x7fc78c616b37]
/lib64/libc.so.6(__fortify_fail+0x0)[0x7fc78c616b00]
/usr/lib64/R/lib/libR.so(+0x1412d1)[0x7fc73f2182d1]

Curiously, if I simply remove the return statement and do return("foo"),
it works fine (but of course I don't get the output I want. So somehow the
process of returning the svg and coercing to the postgresql text causes a
hard crash. It is also odd to me that the regular old "plot" works just
fine. Maybe that means this is a bug in svglite or ggplot2, but it would be
nice if PL/R prevented against server crashes as much as possible. Maybe it
is something about the svg generated by ggplot2 that causes the problem.

As a side note, I am new to PL/R but find it confusing how returning
text often fails. For example, if I have two string and concatenate them,
no dice. That is, this doesn't work:

CREATE OR REPLACE FUNCTION R_test_cat () RETURNS text AS $$
return(cat("foo","bar")) $$ language 'plr';
When running this I get nothing, whereas a simple return("foo bar")
works just fine. If there is something I am going wrong in either of these
cases please advise. Thanks, and appreciate the efforts on PL/R, it is a
very useful modules.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#22 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AAYz9pASxm0ypfkOw1NS8R7w_twQyE2jks5qMfk1gaJpZM4I35LI
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants