diff options
author | Frank Denis <github@pureftpd.org> | 2018-10-14 10:32:48 +0200 |
---|---|---|
committer | Frank Denis <github@pureftpd.org> | 2018-10-14 10:37:18 +0200 |
commit | 15ba7df2245ac177a965346e7ec96a4ab3300839 (patch) | |
tree | 01da6d38709d54a305abb1b74e3c6a11085727fa /ext/sodium | |
parent | d05745816634d82a14bb8abb9c322c8b63be098f (diff) | |
download | php-git-15ba7df2245ac177a965346e7ec96a4ab3300839.tar.gz |
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
Diffstat (limited to 'ext/sodium')
-rw-r--r-- | ext/sodium/libsodium.c | 2 | ||||
-rw-r--r-- | ext/sodium/tests/utils.phpt | 7 |
2 files changed, 8 insertions, 1 deletions
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" |