Opened 9 years ago

Closed 9 years ago

#15363 closed defect (fixed)

MPIR large numbers give a segmentation fault

Reported by: Jeroen Demeyer Owned by:
Priority: major Milestone: sage-5.13
Component: c_lib Keywords:
Cc: Paul Zimmermann 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:

Status badges

Description (last modified by Jeroen Demeyer)

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 Jeroen Demeyer 9 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 9 years ago by Jeroen Demeyer

Description: modified (diff)
Summary: Segfault in exact_rational for RRMPIR large numbers give a segmentation fault

comment:2 Changed 9 years ago by Jeroen Demeyer

Description: modified (diff)

comment:3 Changed 9 years ago by Jeroen Demeyer

Authors: Jeroen Demeyer
Component: basic arithmeticc_lib
Dependencies: #9640

Changed 9 years ago by Jeroen Demeyer

Attachment: 15363_mpir_malloc.patch added

comment:4 Changed 9 years ago by Jeroen Demeyer

Status: newneeds_review

comment:5 Changed 9 years ago by Paul Zimmermann

Status: needs_reviewneeds_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 9 years ago by Jeroen Demeyer

Did you apply the dependency #9640?

comment:7 Changed 9 years ago by Jeroen Demeyer

Dependencies: #9640#14029, #13311, #9640
Status: needs_workneeds_review

comment:8 Changed 9 years ago by Paul Zimmermann

Did you apply the dependency #9640?

obviously not...

Paul

comment:9 Changed 9 years ago by Paul Zimmermann

Reviewers: Paul Zimmermann
Status: needs_reviewpositive_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 9 years ago by Jeroen Demeyer

Merged in: sage-5.13.beta3
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.