[Rd] identify() seg.faults (PR#4057)

Roger.Bivand at nhh.no Roger.Bivand at nhh.no
Wed Sep 3 10:21:53 MEST 2003


Full_Name: Roger Bivand
Version: 1.7.1
OS: i686-pc-linux-gnu
Submission from: (NULL) (129.177.30.18)


identify() seg.faults when x is an empty list, when the n argument is given a
positive value, avoiding the check for non-positive n (n <- length(x) when x is
the non-existent x component of the empty list, and when neither x nor y are
components of the list.

suggested resolution: add test in plot.c around line 3010



> > The simplest case is:

> plot(1:10)
> xy <- list()
> identify(xy, n=1)
Segmentation fault

but 

> identify(xy)
Error in identify.default(xy) : invalid number of points in identify

I'm not sure, but adding a check against zero-length and/or NULL x and or 
y about line 3010 in src/main/plot.c should catch this.

> On Tue, 2 Sep 2003, kjetil brinchmann halvorsen wrote:
>
> > Hola!
> > I will want to identify pixels in an image with the mouse, for 
> > so getting the image data from the matrix(es), for use in subsequent 
> > discriminant analysis. But the following bombs R:
> > (windows XP, rw1071)
> > 
> > > str(baboon)
> >  list()
> >  - attr(*, "size")= int [1:2] 512 512
> >  - attr(*, "cellres")= num [1:2] 1 1
> >  - attr(*, "bbox")= num [1:4] 0 0 512 512
> >  - attr(*, "channels")= chr "grey"
> >  - attr(*, "bbcent")= logi FALSE
> >  - attr(*, "class")= chr "pixmapGrey"
> >  - attr(*, "grey")= num [1:512, 1:512] 0.537 0.510 0.345 0.259 0.322 
> > ...
> > > class(baboon)
> > [1] "pixmapGrey"
> > > library(pixmap)
> > > plot(baboon)
> > > identify(baboon, n=1)
> > 
> > ... and then R bombs!
> > 
> > What to do?
> > > > library(pixmap)
> > example(pixmap)
> ....
> pixmap> plot(z[1:20, 10:40])
> > identify(z, n=1)
> 
> Program received signal SIGSEGV, Segmentation fault.
> do_set (call=0x869ce7c, op=0x8299648, args=0x869ce98, rho=0x8f2496c)
>     at eval.c:1308
> 1308                switch (NAMED(s)) {
> 
> 
> The identify.default() function is passing the pixmap object through to
> xy.coords(), which returns two empty x and y vectors, which are checked
> for length in the R code - xy.coords() treats the pixmap object as a list, 
> does:
> 
> } else if (is.list(x)) {
>     xlab <- paste(ylab, "$x", sep = "")
>     ylab <- paste(ylab, "$y", sep = "")
>     y <- x[["y"]]
>     x <- x[["x"]]
> } else {
> 
> and y and x are the same length, so returns to identify.default() with 
> nothing, which is passed on to the .Internal() undetected. Two 
> possibilities - an identify.pixmap() in pixmap, or a test for the 
> (package, S4) pixmap class in xy.coords. But as it stands, it's a quick 
> way to exit the program. xy.coords() seems to be trusting the user to have 
> a list with x and y components, and here it has neither. The list is 
> indeed empty, being an S4 class - it just has attributes.
>



More information about the R-devel mailing list