Skip to content

Commit 7a02704

Browse files
Metabolixnikic
authored andcommitted
Require strict base64 in data URI
As the tests already show, the data URI wrapper is supposed to fail for corrupt input, but for some reason, one case of invalid input is still allowed to pass?! Strict base64 makes a lot more sense here. Also, Chromium and Firefox fail on invalid base64, so it's a logical choice for PHP as well.
1 parent f775199 commit 7a02704

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

ext/standard/tests/file/stream_rfc2397_006.phpt

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ NULL
2626

2727
Warning: file_get_contents() expects parameter 1 to be a valid path, string given in %s line %d
2828
NULL
29-
string(13) "foobar foobar"
29+
30+
Warning: file_get_contents(data:;base64,#Zm9vYmFyIGZvb2Jhcg==): failed to open stream: rfc2397: unable to decode in %sstream_rfc2397_006.php on line %d
31+
bool(false)
3032

3133
Warning: file_get_contents(data:;base64,#Zm9vYmFyIGZvb2Jhc=): failed to open stream: rfc2397: unable to decode in %sstream_rfc2397_006.php on line %d
3234
bool(false)

main/streams/memory.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ static php_stream * php_stream_url_wrap_rfc2397(php_stream_wrapper *wrapper, con
720720
dlen--;
721721

722722
if (base64) {
723-
base64_comma = php_base64_decode((const unsigned char *)comma, dlen);
723+
base64_comma = php_base64_decode_ex((const unsigned char *)comma, dlen, 1);
724724
if (!base64_comma) {
725725
zval_ptr_dtor(&meta);
726726
php_stream_wrapper_log_error(wrapper, options, "rfc2397: unable to decode");

0 commit comments

Comments
 (0)