Re: Segmentation fault when printing large numbers

2021-04-28 Thread Marc Glisse

On Wed, 28 Apr 2021, Jeff Epler wrote:


The attached program creates a rather large number, then attempts to print
it.  The printing step encounters a segmentation fault.

Typical error traceback as seen by gdb:
Program received signal SIGSEGV, Segmentation fault.
__memmove_avx_unaligned_erms () at
../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:500
500 ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S: No such file
or directory.
(gdb) where
#0  __memmove_avx_unaligned_erms () at
../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:500
#1  0xcb3c in __gmp_asprintf_memory (d=0x7fffe2e0,
str=0x7ffeff624010 "", len=18446744071562067968) at asprntffuns.c:48
#2  0xd042 in __gmp_doprnt_integer (funs=0x55583d80
<__gmp_asprintf_funs_noformat>, data=0x7fffe2e0, p=0x7fffe340,
s=0x7ffeff624010 "") at doprnti.c:125
#3  0x6ad0 in __gmp_doprnt_integer_ostream (o=...,
p=0x7fffe340, s=0x7ffeff624010 "") at osdoprnti.cc:60
#4  0x6a09 in operator<< (o=..., z=0x7fffe3d0) at
osmpz.cc:46
#5  0x6934 in operator<< <__mpz_struct [1], __mpz_struct [1]>
(o=..., expr=...) at ./gmpxx.h:2181
#6  0x6428 in main (argc=2, argv=0x7fffe528) at bigg.c:16

It appears that the character-size of strings at some layer
(__gmp_doprnt_integer?) is restricted to INT_MAX bytes of output.


Using int for the length in that file is certainly a bad sign. Generally, 
formatted I/O hits limitations in GMP, see for instance 
https://gmplib.org/list-archives/gmp-bugs/2015-November/003795.html and 
various other reports. It may be possible to fix some of the printing 
functions without any ABI break, but not others...


--
Marc Glisse
___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs


Segmentation fault when printing large numbers

2021-04-28 Thread Jeff Epler
The attached program creates a rather large number, then attempts to print
it.  The printing step encounters a segmentation fault.

Typical error traceback as seen by gdb:
Program received signal SIGSEGV, Segmentation fault.
__memmove_avx_unaligned_erms () at
../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:500
500 ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S: No such file
or directory.
(gdb) where
#0  __memmove_avx_unaligned_erms () at
../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:500
#1  0xcb3c in __gmp_asprintf_memory (d=0x7fffe2e0,
str=0x7ffeff624010 "", len=18446744071562067968) at asprntffuns.c:48
#2  0xd042 in __gmp_doprnt_integer (funs=0x55583d80
<__gmp_asprintf_funs_noformat>, data=0x7fffe2e0, p=0x7fffe340,
s=0x7ffeff624010 "") at doprnti.c:125
#3  0x6ad0 in __gmp_doprnt_integer_ostream (o=...,
p=0x7fffe340, s=0x7ffeff624010 "") at osdoprnti.cc:60
#4  0x6a09 in operator<< (o=..., z=0x7fffe3d0) at
osmpz.cc:46
#5  0x6934 in operator<< <__mpz_struct [1], __mpz_struct [1]>
(o=..., expr=...) at ./gmpxx.h:2181
#6  0x6428 in main (argc=2, argv=0x7fffe528) at bigg.c:16

It appears that the character-size of strings at some layer
(__gmp_doprnt_integer?) is restricted to INT_MAX bytes of output.

Problem exists with the development version at changeset:
18211:92681f2490cc (April 16) as well as with 6.1.2+dfsg-4 as published by
Debian for Buster.
#include 
#include 
#include 
#include 

using namespace std;

int main(int argc, char **argv) {
for(int i=1; i___
gmp-bugs mailing list
gmp-bugs@gmplib.org
https://gmplib.org/mailman/listinfo/gmp-bugs