[Rd] Patch: fix segfault from empty raster

QRD qrd at sig.com
Mon Sep 16 12:24:35 CEST 2013


Hi,

A colleague recently came across an R crash, which I can boil down to
the following, running under Rgui on Windows 7:

library(ggplot2)
ggplot(data.frame(x=1, y=1, z=4.7), aes(x, y, z=z)) + stat_summary2d()

This reliably causes a segmentation fault.  sessionInfo() below.

What's happening is that (for reasons which I'll discuss with the
ggplot2 developers) the 'colorbar' guide is being built with a zero-size
source raster.

In L_raster() (grid.c), this raster is not a "nativeRaster", so we do

    image = (unsigned int*) R_alloc(n, sizeof(unsigned int));

with n = 0, and R_alloc() gives us a NULL pointer.

The display of this raster requests interpolation, so we end up in
R_GE_rasterInterpolate(), where 'sraster' is NULL, and chaos ensues as
it tries to read source pixels.

It seems to me that it doesn't make sense to display an empty raster, so
I inserted a check in L_raster().  A proof-of-concept patch is attached.
With this patch, R gives an error message instead of a segfault.

Does this seem a sensible change?  If so, could something like it be
incorporated?

Thanks,

Ben.

- - - - 8< - - - -

> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_Ireland.1252  LC_CTYPE=English_Ireland.1252
[3] LC_MONETARY=English_Ireland.1252 LC_NUMERIC=C
[5] LC_TIME=English_Ireland.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] ggplot2_0.9.3.1

loaded via a namespace (and not attached):
 [1] colorspace_1.2-2   compiler_3.0.1     dichromat_2.0-0    digest_0.6.3
 [5] grid_3.0.1         gtable_0.1.2       labeling_0.2       MASS_7.3-26
 [9] munsell_0.4        plyr_1.8           proto_0.3-10       RColorBrewer_1.0-5
[13] reshape2_1.2.2     scales_0.2.3       stringr_0.6.2      tools_3.0.1



More information about the R-devel mailing list