Bug #75178 [NEW]: bcpowmod() misbehaves for non-integer base or modulus

From: Date: Sat, 09 Sep 2017 10:59:00 +0000
Subject: Bug #75178 [NEW]: bcpowmod() misbehaves for non-integer base or modulus
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211016@lists.php.net to get a copy of this message
From:             cmb
Operating system: *
PHP version:      7.0.23
Package:          BC math related
Bug Type:         Bug
Bug description:bcpowmod() misbehaves for non-integer base or modulus

Description:
------------
bcpowmod() accepts non-integral operands, writing a warning to
stderr (see bug #75169) and simply going on for non-integer base
and modulus, while a non-integer exponent is truncated. The
results appear to be nonsensical.

Since bcpowmod() is a simple wrapper for bc_raisemod() which
implements the so called right-to-left binary method for modular
exponentiation[1], the function is unsuitable for non-integral
operands, so the warnings are correct, but base and modulus would
have to be truncated as well.[2]

[1]
<https://en.wikipedia.org/wiki/Modular_exponentiation#Right-to-left_binary_method>
[2]
<https://github.com/php/php-src/blob/php-7.0.23/ext/bcmath/libbcmath/src/raisemod.c#L69>


Test script:
---------------
<?php
var_dump(bcpowmod('4.1', '4', '3', 3));
var_dump(bcpowmod('4', '4', '3.1', 3));


Expected result:
----------------
bc math warning: non-zero scale in base
string(5) "1.000"
bc math warning: non-zero scale in modulus
string(5) "1.000"


Actual result:
--------------
bc math warning: non-zero scale in base
string(5) "0.276"
bc math warning: non-zero scale in modulus
string(5) "0.250"


-- 
Edit bug report at https://bugs.php.net/bug.php?id=75178&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=75178&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=75178&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=75178&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=75178&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=75178&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=75178&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=75178&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=75178&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=75178&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=75178&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=75178&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=75178&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=75178&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75178&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=75178&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=75178&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=75178&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75178&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=75178&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=75178&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#211016) next »