Bug #76291 [Com]: Sodium Base64 no padding variants throw an excepting when decoding

From: Date: Wed, 02 May 2018 10:08:50 +0000
Subject: Bug #76291 [Com]: Sodium Base64 no padding variants throw an excepting when decoding
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215003@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76291&edit=1 ID: 76291 Comment by: james at lucas dot net dot au Reported by: james at lucas dot net dot au Summary: Sodium Base64 no padding variants throw an excepting when decoding Status: Open Type: Bug Package: *Encryption and hash functions Operating System: MacOSX 10.11 PHP Version: 7.2.5 Block user comment: N Private report: N New Comment: This has been fixed upstream with https://github.com/jedisct1/libsodium-php/commit/615bf793623eb3ae0d20cf407153f2d7e2aef9b5 Previous Comments: ------------------------------------------------------------------------ [2018-05-02 01:27:52] james at lucas dot net dot au 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/lo! cal/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 this bug report at https://bugs.php.net/bug.php?id=76291&edit=1

« previous php.bugs (#215003) next »