Opened 6 years ago

Closed 6 years ago

#15363 closed defect (fixed)

MPIR large numbers give a segmentation fault

Reported by: jdemeyer Owned by:
Priority: major Milestone: sage-5.13
Component: c_lib Keywords:
Cc: zimmerma Merged in: sage-5.13.beta3
Authors: Jeroen Demeyer Reviewers: Paul Zimmermann
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #14029, #13311, #9640 Stopgaps:

Description (last modified by jdemeyer)

sage: 2^9223372036854775806
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-9-da1ea00f776d> in <module>()
----> 1 Integer(2)**Integer(9223372036854775806)

/scratch/release/merger/sage-5.12/local/lib/python2.7/site-packages/sage/rings/integer.so in sage.rings.integer.Integer.__pow__ (sage/rings/integer.c:14022)()

RuntimeError: Segmentation fault

This is essentially due to MPIR not checking for errors in malloc() (nor does it have a mechanism for returning errors to the user).

This could be "solved" within Sage by adding checking in sage_mpir_malloc() and friends.

Attachments (1)

15363_mpir_malloc.patch (3.2 KB) - added by jdemeyer 6 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 6 years ago by jdemeyer

  • Description modified (diff)
  • Summary changed from Segfault in exact_rational for RR to MPIR large numbers give a segmentation fault

comment:2 Changed 6 years ago by jdemeyer

  • Description modified (diff)

comment:3 Changed 6 years ago by jdemeyer

  • Authors set to Jeroen Demeyer
  • Component changed from basic arithmetic to c_lib
  • Dependencies set to #9640

Changed 6 years ago by jdemeyer

comment:4 Changed 6 years ago by jdemeyer

  • Status changed from new to needs_review

comment:5 Changed 6 years ago by zimmerma

  • Status changed from needs_review to needs_work

after importing the patch in Sage 5.12, I get with sage -br:

┌────────────────────────────────────────────────────────────────────┐
│ Sage Version 5.12, Release Date: 2013-10-07                        │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
Traceback (most recent call last):
  File "/localdisk/tmp/sage-5.12/local/bin/sage-ipython", line 6, in <module>
    from sage.misc.interpreter import SageTerminalApp
  File "/localdisk/tmp/sage-5.12/local/lib/python2.7/site-packages/sage/misc/interpreter.py", line 67, in <module>
    import os, log, re, new, sys
  File "/localdisk/tmp/sage-5.12/local/lib/python2.7/site-packages/sage/misc/log.py", line 66, in <module>
    import misc
  File "/localdisk/tmp/sage-5.12/local/lib/python2.7/site-packages/sage/misc/misc.py", line 39, in <module>
    import sage.misc.prandom as random
  File "/localdisk/tmp/sage-5.12/local/lib/python2.7/site-packages/sage/misc/prandom.py", line 58, in <module>
    from sage.misc.randstate import current_randstate
ImportError: /localdisk/tmp/sage-5.12/local/lib/libcsage.so: undefined symbol: sig_error
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/localdisk/tmp/sage-5.12/local/lib/python/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/localdisk/tmp/sage-5.12/local/lib/python2.7/site-packages/sage/misc/temporary_file.py", line 51, in delete_tmpfiles
    from sage.misc.misc import SAGE_TMP
  File "/localdisk/tmp/sage-5.12/local/lib/python2.7/site-packages/sage/misc/misc.py", line 39, in <module>
    import sage.misc.prandom as random
  File "/localdisk/tmp/sage-5.12/local/lib/python2.7/site-packages/sage/misc/prandom.py", line 58, in <module>
    from sage.misc.randstate import current_randstate
ImportError: /localdisk/tmp/sage-5.12/local/lib/libcsage.so: undefined symbol: sig_error
Error in sys.exitfunc:
Traceback (most recent call last):
  File "/localdisk/tmp/sage-5.12/local/lib/python/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/localdisk/tmp/sage-5.12/local/lib/python2.7/site-packages/sage/misc/temporary_file.py", line 51, in delete_tmpfiles
    from sage.misc.misc import SAGE_TMP
  File "/localdisk/tmp/sage-5.12/local/lib/python2.7/site-packages/sage/misc/misc.py", line 39, in <module>
    import sage.misc.prandom as random
  File "/localdisk/tmp/sage-5.12/local/lib/python2.7/site-packages/sage/misc/prandom.py", line 58, in <module>
    from sage.misc.randstate import current_randstate
ImportError: /localdisk/tmp/sage-5.12/local/lib/libcsage.so: undefined symbol: sig_error

Paul

comment:6 Changed 6 years ago by jdemeyer

Did you apply the dependency #9640?

comment:7 Changed 6 years ago by jdemeyer

  • Dependencies changed from #9640 to #14029, #13311, #9640
  • Status changed from needs_work to needs_review

comment:8 Changed 6 years ago by zimmerma

Did you apply the dependency #9640?

obviously not...

Paul

comment:9 Changed 6 years ago by zimmerma

  • Reviewers set to Paul Zimmermann
  • Status changed from needs_review to positive_review

the example in the description no longer gives a Seg. fault, all doctests still pass, I'm not an expert of the Python-C interface but nevertheless the patch looks fine to me, thus I give a positive review.

Paul

comment:10 Changed 6 years ago by jdemeyer

  • Merged in set to sage-5.13.beta3
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.