Skip to content

Commit 15ba7df

Browse files
committed
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
1 parent d057458 commit 15ba7df

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

ext/sodium/libsodium.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2780,7 +2780,7 @@ PHP_FUNCTION(sodium_base642bin)
27802780
"invalid base64 variant identifier", 0);
27812781
return;
27822782
}
2783-
bin_len = b64_len / 4U * 3U;
2783+
bin_len = b64_len / 4U * 3U + 1U;
27842784
bin = zend_string_alloc(bin_len, 0);
27852785
if (sodium_base642bin((unsigned char *) ZSTR_VAL(bin), bin_len,
27862786
b64, b64_len,

ext/sodium/tests/utils.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ if (defined('SODIUM_BASE64_VARIANT_ORIGINAL')) {
8686
} catch (Exception $e) {
8787
var_dump('base64("O") case passed');
8888
}
89+
var_dump(sodium_base642bin('YWJjZA', SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING));
90+
} else {
91+
var_dump('base64("O1R") case passed');
92+
var_dump('base64("O1") case passed');
93+
var_dump('base64("O") case passed');
94+
var_dump('abcd');
8995
}
9096

9197
?>
@@ -107,3 +113,4 @@ bool(true)
107113
string(25) "base64("O1R") case passed"
108114
string(24) "base64("O1") case passed"
109115
string(23) "base64("O") case passed"
116+
string(4) "abcd"

0 commit comments

Comments
 (0)