From: Frank Denis Date: Sun, 14 Oct 2018 08:32:48 +0000 (+0200) Subject: ext/sodium: Use a correct max output size for base64 decoding X-Git-Tag: php-7.3.0RC4~24^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=15ba7df2245ac177a965346e7ec96a4ab3300839;p=php ext/sodium: Use a correct max output size for base64 decoding Also handle the case where the function is not available in test. Backport from PECL libsodium-php 2.0.12 --- diff --git a/ext/sodium/libsodium.c b/ext/sodium/libsodium.c index 08ac0f9ab2..a5f892fb7a 100644 --- a/ext/sodium/libsodium.c +++ b/ext/sodium/libsodium.c @@ -2780,7 +2780,7 @@ PHP_FUNCTION(sodium_base642bin) "invalid base64 variant identifier", 0); return; } - bin_len = b64_len / 4U * 3U; + bin_len = b64_len / 4U * 3U + 1U; bin = zend_string_alloc(bin_len, 0); if (sodium_base642bin((unsigned char *) ZSTR_VAL(bin), bin_len, b64, b64_len, diff --git a/ext/sodium/tests/utils.phpt b/ext/sodium/tests/utils.phpt index ff380ff78c..4f99f75671 100644 --- a/ext/sodium/tests/utils.phpt +++ b/ext/sodium/tests/utils.phpt @@ -86,6 +86,12 @@ if (defined('SODIUM_BASE64_VARIANT_ORIGINAL')) { } catch (Exception $e) { var_dump('base64("O") case passed'); } + var_dump(sodium_base642bin('YWJjZA', SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING)); +} else { + var_dump('base64("O1R") case passed'); + var_dump('base64("O1") case passed'); + var_dump('base64("O") case passed'); + var_dump('abcd'); } ?> @@ -107,3 +113,4 @@ bool(true) string(25) "base64("O1R") case passed" string(24) "base64("O1") case passed" string(23) "base64("O") case passed" +string(4) "abcd"