Skip to content

wrong type of text crashes the server #22

Description

@rmesser

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions