Bug #76291 [NEW]: Sodium Base64 no padding variants throw an excepting when decoding
| From: | james at lucas dot net dot au | Date: | Wed, 02 May 2018 01:27:58 +0000 |
| Subject: | Bug #76291 [NEW]: Sodium Base64 no padding variants throw an excepting when decoding | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-215000@lists.php.net to get a copy of this message | ||
From: james at lucas dot net dot au
Operating system: MacOSX 10.11
PHP version: 7.2.5
Package: *Encryption and hash functions
Bug Type: Bug
Bug description:Sodium Base64 no padding variants throw an excepting when decoding
Description:
------------
sodium_base642bin is unable to decode the base64 when using the no
padding variants. This can be shown quickly by passing the output from
the sodium_bin2base64 no padding variants directly to the base642bin
Configure Command => './configure'
'--prefix=/usr/local/Cellar/php/7.2.5' '--localstatedir=/usr/local/var'
'--sysconfdir=/usr/local/etc/php/7.2'
'--with-config-file-path=/usr/local/etc/php/7.2'
'--with-config-file-scan-dir=/usr/local/etc/php/7.2/conf.d'
'--with-pear=/usr/local/Cellar/php/7.2.5/share/php/pear'
'--enable-bcmath' '--enable-calendar' '--enable-dba'
'--enable-dtrace'
'--enable-exif' '--enable-ftp' '--enable-fpm'
'--enable-intl'
'--enable-mbregex' '--enable-mbstring' '--enable-mysqlnd'
'--enable-opcache-file' '--enable-pcntl' '--enable-phpdbg'
'--enable-phpdbg-webhelper' '--enable-shmop' '--enable-soap'
'--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem'
'--enable-sysvshm' '--enable-wddx' '--enable-zip'
'--with-apxs2=/usr/local/opt/httpd/bin/apxs' '--with-bz2'
'--with-fpm-user=_www' '--with-fpm-group=_www'
'--with-freetype-dir=/usr/local/opt/freetype' '--with-gd'
'--with-gettext=/usr/local/opt/gettext' '--with-gmp=/usr/local/opt/gmp'
'--with-icu-dir=/usr/local/opt/icu4c'
'--with-jpeg-dir=/usr/local/opt/jpeg' '--with-kerberos'
'--with-layout=GNU' '--with-ldap' '--with-ldap-sasl'
'--with-libedit'
'--with-libzip' '--with-mhash' '--with-mysql-sock=/tmp/mysql.sock'
'--with-mysqli=mysqlnd' '--with-ndbm'
'--with-openssl=/usr/local/opt/openssl'
'--with-password-argon2=/usr/local/opt/argon2'
'--with-pdo-dblib=/usr/local/opt/freetds' '--with-pdo-mysql=mysqlnd'
'--with-pdo-odbc=unixODBC,/usr/local/opt/unixodbc'
'--with-pdo-pgsql=/usr/local/opt/libpq'
'--with-pgsql=/usr/local/opt/libpq' '--with-pic'
'--with-png-dir=/usr/local/opt/libpng'
'--with-pspell=/usr/local/opt/aspell'
'--with-sodium=/usr/local/opt/libsodium'
'--with-unixODBC=/usr/local/opt/unixodbc'
'--with-webp-dir=/usr/local/opt/webp' '--with-xmlrpc' '--with-xsl'
'--with-zlib' '--with-curl'
sodium
sodium support => enabled
libsodium headers version => 1.0.16
libsodium library version => 1.0.16
Test script:
---------------
<?php
$variants = [ 'SODIUM_BASE64_VARIANT_ORIGINAL' =>
SODIUM_BASE64_VARIANT_ORIGINAL,
'SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING' =>
SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING,
'SODIUM_BASE64_VARIANT_URLSAFE' => SODIUM_BASE64_VARIANT_URLSAFE,
'SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING' =>
SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING ];
foreach($variants as $variant => $flag)
{
try {
$base64 = sodium_bin2base64("abcd", $flag);
echo $variant . " base64: " . $base64 . "\n";
echo $variant . ": " . sodium_base642bin($base64, $flag) . "\n";
} catch (SodiumException $ex) {
echo $variant . ": " . $ex->getMessage() . "\n";
}
}
Expected result:
----------------
SODIUM_BASE64_VARIANT_ORIGINAL base64: YWJjZA==
SODIUM_BASE64_VARIANT_ORIGINAL: abcd
SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING base64: YWJjZA
SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING: abcd
SODIUM_BASE64_VARIANT_URLSAFE base64: YWJjZA==
SODIUM_BASE64_VARIANT_URLSAFE: abcd
SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING base64: YWJjZA
SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING: abcd
Actual result:
--------------
SODIUM_BASE64_VARIANT_ORIGINAL base64: YWJjZA==
SODIUM_BASE64_VARIANT_ORIGINAL: abcd
SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING base64: YWJjZA
SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING: invalid base64 string
SODIUM_BASE64_VARIANT_URLSAFE base64: YWJjZA==
SODIUM_BASE64_VARIANT_URLSAFE: abcd
SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING base64: YWJjZA
SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING: invalid base64 string
--
Edit bug report at https://bugs.php.net/bug.php?id=76291&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76291&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76291&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76291&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76291&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76291&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76291&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76291&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76291&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76291&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76291&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76291&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76291&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76291&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76291&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76291&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76291&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76291&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76291&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76291&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76291&r=mysqlcfg