Bug 15883 - Setting options(device) to a non-device function segfaults
Summary: Setting options(device) to a non-device function segfaults
Alias: None
Product: R
Classification: Unclassified
Component: Graphics (show other bugs)
Version: R 3.1.0
Hardware: Other Linux
: P5 normal
Assignee: R-core
Depends on:
Reported: 2014-07-15 15:13 UTC by Barry Rowlingson
Modified: 2017-08-01 12:13 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Barry Rowlingson 2014-07-15 15:13:04 UTC
Setting options(device) to something dumb then plotting causes a segfault:

> options(device=function(...){});plot(1)

 *** caught segfault ***
address 0x1b0, cause 'memory not mapped'

 1: dev.hold()
 2: plot.default(1)
 3: plot(1)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit

Yes, doing a dumb thing is dumb but if someone is developing new graphics devices then it might be nice if it was robust to things like this. I suspect the graphics system doesn't know that options(device) hasn't created a graphics device structure and blunders on regardless, smashing memory in the process.

Also happens on Windows and Mac.

> sessionInfo()
R version 3.1.1 (2014-07-10)
Platform: x86_64-unknown-linux-gnu (64-bit)

 [1] LC_CTYPE=en_GB.utf8       LC_NUMERIC=C             
 [3] LC_TIME=en_GB.utf8        LC_COLLATE=en_GB.utf8    
 [5] LC_MONETARY=en_GB.utf8    LC_MESSAGES=en_GB.utf8   
 [7] LC_PAPER=en_GB.utf8       LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
Comment 1 Martin Maechler 2017-08-01 12:13:47 UTC
I don't know why this has never been answered.
As you say "it is a dumb thing", but we agree that it is bug for R to segfault.

Note this is not related to base graphics; but rather to the general "graphics device" handling  (with user level interface in package "grdevices"); so this fails equivalently:

options(device=function(...){}); ggplot2::qplot(1 ~ 1)

Interestingly, the originally (pre-grid,..) only function to start graphics, the 
base graphics
does not segfault but gives a correct error message:

So now I see how a clean bug fix will work.
Will fix this in  R-devel and  R 3.4.1 patched.