octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #36067] bug in exist() when checking for a fau


From: Kris Thielemans
Subject: [Octave-bug-tracker] [bug #36067] bug in exist() when checking for a faulty mex/oct file
Date: Sat, 10 Aug 2013 20:58:09 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0

Follow-up Comment #8, bug #36067 (project octave):

I have checked this with the current check-out, and indeed I see no problem
with my previous test case. 

However, I can create the same problem with a different mex file, see new
attachment causesegfault.cpp. The difference here is that the (intentional)
segmentation fault is caused by the initialisation of a static global
variable. This code has to be run before any mex function, so it makes sense
that it is executed when loading the mex file.

Clearly, this mex file is faulty, but it is used here as illustration of
strange behaviour of exist().

With this mex file in the octave path, executing the following octave gives

octave:1> exist("causesegfault.bla","file")
will crash now
panic: Segmentation fault -- stopping myself...
Segmentation fault

I did compile octave with -g this time around, and can confirm that the
stack-trace shows the crash occurs in the call to safe_symbol_lookup in
symbol_exist (in libinterp/corefcn/variables.cc). This is called with argument
"causesegfault" (because everything after the "." is stripped first as Rik
said). (There's nothing wrong with safe_symbol_lookup in my opinion. Somewhere
down the line it will call dlopen on the mex file, which will then cause the
static variables to be initialised).

So... summary of all this. exist("arg.ext", "file") will load arg.mex or
arg.oct, and hence initialise things inside the mex/oct file. 

This is certainly surprising to me. It also causes a performance penalty as
exist("arg.ext","file") really shouldn't be looking for anything with "arg" at
all. 

I'm not sure if you think this is worth fixing but I see 2 possible
solutions:

- put the code testing for files first if the 2nd argument is "file". However,
this is only a partial solution as it would still have the same problem when
just using exist("causesegfault.bla")

- at the start of the symbol_exist function, before simply removing the
extension, we could check if the extension is "m","mex" or "oct" (ignoring
case?). If it isn't, we can skip everything involving symbol_name. I think
this should be alright and be backwards compatible (at least, for intended use
cases), but am not 100% sure.

(file #28806)
    _______________________________________________________

Additional Item Attachment:

File name: causesegfault.cpp              Size:0 KB


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?36067>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]