]> 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)
NEWS
ext/standard/base64.c
ext/standard/tests/url/bug55273.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 0118542110b80c57a207a774c033e42d659c1bc8..c6506b4e74a4c118b4c1388185d58d4c387d4457 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ PHP                                                                        NEWS
     condition. (Gustavo)
   . Fixed bug #55504 (Content-Type header is not parsed correctly on
     HTTP POST request). (Hannes)
+  . Fixed bug #55273 (base64_decode() with strict rejects whitespace after
+    pad). (Ilia)
 
 - Curl:
   . Fixed bug #54798 (Segfault when CURLOPT_STDERR file pointer is closed
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"