fuzzylogician / gmpy

Automatically exported from code.google.com/p/gmpy
GNU Lesser General Public License v3.0
0 stars 0 forks source link

Buffer overflow for mpc in the REPL when the precision is too big. #93

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. from gmpy2 import get_context, log
2. get_context().precision=400
3. log(2+1j)

What is the expected output? What do you see instead?

Expect to get log(2+1j) with 400 places for both real and imaginary parts.
Got: *** buffer overflow detected ***: /usr/bin/python3.3 terminated
Backtrace...

What version of the product are you using? On what operating system?

Using gmpy-2.0.4 on Unix, with python3.3.

Please provide any additional information below.

This is due to a buffer overflow on sprintf() from gmpy_convert.c.
A true workaround would be to use asprintf(), but for most reasonable uses, 
using a bigger string buffer would be enough.

Original issue reported on code.google.com by bernardo...@gmail.com on 4 Dec 2014 at 10:25

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for the bug report and the patch. The bug specifically impacts repr(mpc) 
when the precision is greater than 325 bits. I use fmtstr[30] in several 
locations. Even though I don't think the other locations can overflow, I 
changed all of them to fmtstr[60] for consistency. 

Fix is in r1018.

I'll let you know when I release 2.0.5.

Case

Original comment by casevh on 5 Dec 2014 at 3:41

GoogleCodeExporter commented 8 years ago
I have released version 2.0.5 which includes the fix.

I'm sorry it has taken so long to release the new version.

Case

Original comment by casevh on 13 Jan 2015 at 5:48