]> granicus.if.org Git - php/commitdiff
ext/sodium: Use a correct max output size for base64 decoding
authorFrank Denis <github@pureftpd.org>
Sun, 14 Oct 2018 08:32:48 +0000 (10:32 +0200)
committerFrank Denis <github@pureftpd.org>
Sun, 14 Oct 2018 08:37:18 +0000 (10:37 +0200)
Also handle the case where the function is not available in test.

Backport from PECL libsodium-php 2.0.12

ext/sodium/libsodium.c
ext/sodium/tests/utils.phpt

index 08ac0f9ab2181ac15fd8ca56ced718c011c184bf..a5f892fb7a371f5a63710b2b563030fd6559efe1 100644 (file)
@@ -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,
index ff380ff78ca3ef74f2d4a3131a3534e3323e49c5..4f99f75671a604becd1a54be39247cf5e415a88a 100644 (file)
@@ -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"