Bug 14931 - simpleError segFault
simpleError segFault
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Low-level
R 2.15.0
All All
: P5 critical
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-05-29 17:00 UTC by Robert McGehee
Modified: 2012-05-30 20:46 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert McGehee 2012-05-29 17:00:02 UTC
On both my Mac and Linux installations the following script consistently causes a segfault when run non-interactively.

## contents of crash.R
test <- function() stop(simpleError("Error", "xyz"))
test()
## End

> R --vanilla < crash.R
 *** caught segfault ***
address 0x1, cause 'memory not mapped'

Traceback:
 1: stop(simpleError("Error", "xyz"))
 2: test()
aborting ...
Segmentation fault

Let me know if you need any other information.
--Robert

R.version
               _                            
platform       x86_64-pc-linux-gnu          
arch           x86_64                       
os             linux-gnu                    
system         x86_64, linux-gnu            
status                                      
major          2                            
minor          15.0                         
year           2012                         
month          03                           
day            30                           
svn rev        58871                        
language       R                            
version.string R version 2.15.0 (2012-03-30)
nickname
Comment 1 Peter Dalgaard 2012-05-29 17:38:50 UTC
confirmed on OSX, 2.14.2 (32, 64 bits) and r-devel

running under debugger, I see


> test <- function() stop(simpleError("Error", "xyz"))
> test()

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000001
0x00000001000b6d66 in R_ConciseTraceback (call=0x1031774e8, skip=0) at ../../../R/src/main/errors.c:1391
1391		    CHAR(PRINTNAME(fun)) : "<Anonymous>";
(gdb) l
1386	    /* However: do we want to include the call in the list if it is a
1387	       primitive? */
1388	    if (ncalls == 1 && call != R_NilValue) {
1389		SEXP fun = CAR(call);
1390		const char *this = (TYPEOF(fun) == SYMSXP) ?
1391		    CHAR(PRINTNAME(fun)) : "<Anonymous>";
1392		if(streql(buf, this)) return "";
1393	    }
1394	    return buf;
1395	}
(gdb) 


and the value of "fun" is indeed 0x1 at that point
Comment 2 Duncan Murdoch 2012-05-30 15:14:58 UTC
On 12-05-29 12:38 PM, r-bugs@r-project.org wrote:
> https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14931
>
> Peter Dalgaard<pd.mes@cbs.dk>  changed:
>
>             What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                   CC|                            |pd.mes@cbs.dk
>
> --- Comment #1 from Peter Dalgaard<pd.mes@cbs.dk>  2012-05-29 12:38:50 EDT ---
> confirmed on OSX, 2.14.2 (32, 64 bits) and r-devel
>
> running under debugger, I see
>
>
>> test<- function() stop(simpleError("Error", "xyz"))
>> test()
>
> Program received signal EXC_BAD_ACCESS, Could not access memory.
> Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000001
> 0x00000001000b6d66 in R_ConciseTraceback (call=0x1031774e8, skip=0) at
> ../../../R/src/main/errors.c:1391
> 1391            CHAR(PRINTNAME(fun)) : "<Anonymous>";
> (gdb) l
> 1386        /* However: do we want to include the call in the list if it is a
> 1387           primitive? */
> 1388        if (ncalls == 1&&  call != R_NilValue) {
> 1389        SEXP fun = CAR(call);
> 1390        const char *this = (TYPEOF(fun) == SYMSXP) ?
> 1391            CHAR(PRINTNAME(fun)) : "<Anonymous>";
> 1392        if(streql(buf, this)) return "";
> 1393        }
> 1394        return buf;
> 1395    }
> (gdb)
>
>
> and the value of "fun" is indeed 0x1 at that point
>


I don't think this is related to my recent changes there, but I'll take 
a look.

Duncan Murdoch


Comment 3 Duncan Murdoch 2012-05-31 00:12:25 UTC
On 29/05/2012 12:38 PM, r-bugs@r-project.org wrote:
> https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=14931
>
> Peter Dalgaard<pd.mes@cbs.dk>  changed:
>
>             What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                   CC|                            |pd.mes@cbs.dk
>
> --- Comment #1 from Peter Dalgaard<pd.mes@cbs.dk>  2012-05-29 12:38:50 EDT ---
> confirmed on OSX, 2.14.2 (32, 64 bits) and r-devel
>
> running under debugger, I see
>
>
> >  test<- function() stop(simpleError("Error", "xyz"))
> >  test()
>
> Program received signal EXC_BAD_ACCESS, Could not access memory.
> Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000001
> 0x00000001000b6d66 in R_ConciseTraceback (call=0x1031774e8, skip=0) at
> ../../../R/src/main/errors.c:1391
> 1391            CHAR(PRINTNAME(fun)) : "<Anonymous>";
> (gdb) l
> 1386        /* However: do we want to include the call in the list if it is a
> 1387           primitive? */
> 1388        if (ncalls == 1&&  call != R_NilValue) {
> 1389        SEXP fun = CAR(call);
> 1390        const char *this = (TYPEOF(fun) == SYMSXP) ?
> 1391            CHAR(PRINTNAME(fun)) : "<Anonymous>";
> 1392        if(streql(buf, this)) return "";
> 1393        }
> 1394        return buf;
> 1395    }
> (gdb)
>
>
> and the value of "fun" is indeed 0x1 at that point

The problem is that the "call" in the C code is the string "xyz" from 
the second argument to simpleError.  This is user error (the docs say 
the call should be a call), but it shouldn't segfault.  I'll put in a 
sanity check.

If anyone thinks simpleError("Error", call = "xyz") should be accepted, 
let me know how you think it should be handled.

Duncan Murdoch