|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27258 gmp_powm: fix for bug #27172 breaks large (> 31 bit on i386) modulos
Submitted: 2004-02-15 01:14 UTC Modified: 2004-02-15 12:16 UTC
From: oscar at the-rileys dot net Assigned: iliaa (profile)
Status: Closed Package: Math related
PHP Version: 4CVS,5CVS OS: NetBSD 1.6
Private report: No CVE-ID: None
 [2004-02-15 01:14 UTC] oscar at the-rileys dot net
The fix for bug #27172 (possible floating-point 
exception in gmp_powm) breaks the function with modulos 
longer than 31 bits.  This is because the modulo 
argument is converted (destructively) to a long before 
it is fetched as a GMP number.  The problem is rectified 
by moving the block that checks for a zero modulo to a 
point after the argument is fetched for use in the 

I have posted a diff here:

I have tested this on my own server, and it appears to 
fix the problem with at least 1024-bit modulos and still 
guards against 0 modulos - test for yourself to be sure, 
of course,

Reproduce code:
This is the example code from the documentation page for gpm_powm:

?? $pow1 = gmp_powm("2", "31", "2147483649");
?? echo gmp_strval($pow1) . "\n";

Expected result:
The number 2147483648 should be output.

Actual result:
The number 1 is output.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-15 01:17 UTC] oscar at the-rileys dot net
I neglected to mention that this is vs. CVS snapshot 
200402142230.  The original bugfix that caused the 
problem was submitted on 2/8/04.
 [2004-02-15 12:16 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 25 00:01:30 2024 UTC