Opened 3 years ago

Closed 3 years ago

#25028 closed defect (worksforme)

pari('f(x)=f(x)')(0) crashes Sage

Reported by: pbruin Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: interfaces Keywords: pari
Cc: jdemeyer Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

In SageMath 8.2.beta8:

sage: pari('f(x)=f(x)')(0)
Segmentation fault

In GP, this causes a "deep recursion" error:

? f(x)=f(x)
%1 = (x)->f(x)
? f(0)
  ***   [...] at: f(x)
  ***             ^----
  ***   in function f: f(x)
  ***                  ^----
  ***   in function f: f(x)
  ***                  ^----
[...]
  ***   in function f: f(x)
  ***                  ^----
  ***   deep recursion.

Change History (6)

comment:1 follow-up: Changed 3 years ago by jdemeyer

This might be fixed by #21509.

comment:2 in reply to: ↑ 1 ; follow-ups: Changed 3 years ago by pbruin

Replying to jdemeyer:

This might be fixed by #21509.

Indeed, #21509 improves the situation:

sage: pari('f(x)=f(x)')(0)
---------------------------------------------------------------------------
SignalError                               Traceback (most recent call last)
<ipython-input-1-0459c960a64f> in <module>()
----> 1 pari('f(x)=f(x)')(Integer(0))

cypari2/gen.pyx in cypari2.gen.Gen.__call__()

cypari2/gen.pyx in cypari2.gen.Gen.eval()

SignalError: Segmentation fault

This is not yet as informative as the GP "deep recursion" error. I tried to do sage --gdb to find out where the segmentation fault comes from, but this appears to crash in cysignals on startup:

$ sage --gdb
SageMath version 8.2.rc0, Release Date: 2018-03-28
GNU gdb (GDB) 7.8.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from python...done.
Traceback (most recent call last):
  File "<string>", line 11, in <module>
ImportError: No module named Cython.Debugger
/tmp/tmpMZ0m4_:19: Error in sourced command file:
Error while executing Python code.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff03a1700 (LWP 54915)]

Program received signal SIGFPE, Arithmetic exception.
0x00007ffff77af269 in raise () from /lib/x86_64-linux-gnu/libpthread.so.0
(gdb) bt
#0  0x00007ffff77af269 in raise () from /lib/x86_64-linux-gnu/libpthread.so.0
#1  0x00007fffeedc5d6a in setup_cysignals_handlers () at build/src/cysignals/implementation.c:381
#2  0x00007fffeedc934c in __pyx_pf_9cysignals_7signals_2init_cysignals (__pyx_self=<optimized out>) at build/src/cysignals/signals.c:2540
#3  __pyx_pw_9cysignals_7signals_3init_cysignals (__pyx_self=<optimized out>, unused=<optimized out>) at build/src/cysignals/signals.c:2426
#4  0x00007ffff7a10d53 in PyObject_Call (func=func@entry=0x7fffef03c890, arg=arg@entry=0x7ffff7f9f050, kw=kw@entry=0x0) at Objects/abstract.c:2547
#5  0x00007ffff7ac211a in do_call (nk=<optimized out>, na=<optimized out>, pp_stack=0x7fffffffb430, func=<optimized out>) at Python/ceval.c:4574
#6  call_function (oparg=<optimized out>, pp_stack=0x7fffffffb430) at Python/ceval.c:4379
#7  PyEval_EvalFrameEx (f=f@entry=0xfc45a0, throwflag=throwflag@entry=0) at Python/ceval.c:2994
#8  0x00007ffff7aca578 in PyEval_EvalCodeEx (co=co@entry=0x7fffef005430, globals=globals@entry=0x7fffef011280, locals=locals@entry=0x7fffef011280, args=args@entry=0x0,
    argcount=argcount@entry=0, kws=kws@entry=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3589
#9  0x00007ffff7aca789 in PyEval_EvalCode (co=co@entry=0x7fffef005430, globals=globals@entry=0x7fffef011280, locals=locals@entry=0x7fffef011280) at Python/ceval.c:669
#10 0x00007ffff7adc8dc in PyImport_ExecCodeModuleEx (name=name@entry=0xfd0920 "cysignals", co=co@entry=0x7fffef005430,
    pathname=pathname@entry=0xfd53e0 "/home/bruinpj/src/sage/local/lib/python2.7/site-packages/cysignals/__init__.pyc") at Python/import.c:731
#11 0x00007ffff7adcb62 in load_source_module (name=0xfd0920 "cysignals",
    pathname=0xfd53e0 "/home/bruinpj/src/sage/local/lib/python2.7/site-packages/cysignals/__init__.pyc", fp=<optimized out>) at Python/import.c:1121
#12 0x00007ffff7ade136 in load_package (name=0xfd0920 "cysignals", pathname=<optimized out>) at Python/import.c:1188
#13 0x00007ffff7addbf1 in import_submodule (mod=mod@entry=0x7ffff7d8ee20 <_Py_NoneStruct>, subname=subname@entry=0xfd0920 "cysignals",
    fullname=fullname@entry=0xfd0920 "cysignals") at Python/import.c:2725
#14 0x00007ffff7ade972 in load_next (p_buflen=<synthetic pointer>, buf=0xfd0920 "cysignals", p_name=<synthetic pointer>, altmod=0x7ffff7d8ee20 <_Py_NoneStruct>,
    mod=0x7ffff7d8ee20 <_Py_NoneStruct>) at Python/import.c:2539
#15 import_module_level (locals=<optimized out>, level=<optimized out>, fromlist=0x7fffef002eb0, globals=<optimized out>, name=<optimized out>) at Python/import.c:2247
#16 PyImport_ImportModuleLevel (name=0x7fffef0121dc "cysignals.signals", globals=<optimized out>, locals=<optimized out>, fromlist=0x7fffef002eb0, level=<optimized out>)
    at Python/import.c:2312
#17 0x00007ffff7abe904 in builtin___import__ (self=<optimized out>, args=<optimized out>, kwds=<optimized out>) at Python/bltinmodule.c:49
#18 0x00007ffff7a10d53 in PyObject_Call (func=func@entry=0x7ffff7fd2fc8, arg=arg@entry=0x7fffef493b90, kw=<optimized out>) at Objects/abstract.c:2547
#19 0x00007ffff7ac0347 in PyEval_CallObjectWithKeywords (func=func@entry=0x7ffff7fd2fc8, arg=arg@entry=0x7fffef493b90, kw=kw@entry=0x0) at Python/ceval.c:4226
#20 0x00007ffff7ac3260 in PyEval_EvalFrameEx (f=f@entry=0xf19bc0, throwflag=throwflag@entry=0) at Python/ceval.c:2628
#21 0x00007ffff7aca578 in PyEval_EvalCodeEx (co=co@entry=0x7fffef003ab0, globals=globals@entry=0x7fffef010a28, locals=locals@entry=0x7fffef010a28, args=args@entry=0x0,
    argcount=argcount@entry=0, kws=kws@entry=0x0, kwcount=0, defs=0x0, defcount=0, closure=0x0) at Python/ceval.c:3589
#22 0x00007ffff7aca789 in PyEval_EvalCode (co=co@entry=0x7fffef003ab0, globals=globals@entry=0x7fffef010a28, locals=locals@entry=0x7fffef010a28) at Python/ceval.c:669
#23 0x00007ffff7adc8dc in PyImport_ExecCodeModuleEx (name=name@entry=0xfc5790 "sage.all", co=co@entry=0x7fffef003ab0,
    pathname=pathname@entry=0xfcf910 "/home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/all.pyc") at Python/import.c:731
#24 0x00007ffff7adcb62 in load_source_module (name=0xfc5790 "sage.all", pathname=0xfcf910 "/home/bruinpj/src/sage/local/lib/python2.7/site-packages/sage/all.pyc",
    fp=<optimized out>) at Python/import.c:1121

comment:3 in reply to: ↑ 2 Changed 3 years ago by jdemeyer

Replying to pbruin:

this appears to crash in cysignals on startup:

That SIGFPE is a feature, not a bug. You are not the first person to stumble over this. Unfortunately, I have no way to tell gdb "this SIGFPE is really part of the normal flow of execution, just ignore it".

comment:4 in reply to: ↑ 2 Changed 3 years ago by jdemeyer

Replying to pbruin:

This is not yet as informative as the GP "deep recursion" error.

True, but it's not so easy to check whether a SIGSEGV was due to a stack overflow or another problem. Once a program has started, the stack is just a region of memory and overflowing the stack is the same as overflowing an allocated array.

I'm not saying that it's impossible to check specifically for stack overflows, but it's going to be a hack anyway. So I doubt that it is worth it.

Last edited 3 years ago by jdemeyer (previous) (diff)

comment:5 Changed 3 years ago by pbruin

I see, cypari2 explicitly disables PARI's own stack checking. It's probably not worth hacking together a substitute for this.

comment:6 Changed 3 years ago by jdemeyer

  • Milestone changed from sage-8.2 to sage-duplicate/invalid/wontfix
  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.