]> granicus.if.org Git - php/commitdiff
Fixed bug #55273 (base64_decode() with strict rejects whitespace after pad)
authorIlia Alshanetsky <iliaa@php.net>
Mon, 12 Sep 2011 17:20:24 +0000 (17:20 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Mon, 12 Sep 2011 17:20:24 +0000 (17:20 +0000)
ext/standard/base64.c
ext/standard/tests/url/bug55273.phpt [new file with mode: 0644]

index 0f261468f422411b3f91b71eafd1d9a33f1bf525..34fb4dd8a27c9af5aef88d97e889d2c1d48642ba 100644 (file)
@@ -153,6 +153,14 @@ PHPAPI unsigned char *php_base64_decode_ex(const unsigned char *str, int length,
        while ((ch = *current++) != '\0' && length-- > 0) {
                if (ch == base64_pad) {
                        if (*current != '=' && ((i % 4) == 1 || (strict && length > 0))) {
+                               if ((i % 4) != 1) {
+                                       while (isspace(*(++current))) {
+                                               continue;
+                                       }
+                                       if (*current == '\0') {
+                                               continue;
+                                       }
+                               }
                                efree(result);
                                return NULL;
                        }
diff --git a/ext/standard/tests/url/bug55273.phpt b/ext/standard/tests/url/bug55273.phpt
new file mode 100644 (file)
index 0000000..1408506
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Bug #55273 (base64_decode() with strict rejects whitespace after pad)
+--FILE--
+<?php
+function test($s) {
+       $v = chunk_split(base64_encode($s));
+       $r = base64_decode($v, True);
+       var_dump($v, $r);
+}
+
+test('PHP');
+test('PH');
+test('P');
+
+?>
+--EXPECT--
+string(6) "UEhQ
+"
+string(3) "PHP"
+string(6) "UEg=
+"
+string(2) "PH"
+string(6) "UA==
+"
+string(1) "P"