]> granicus.if.org Git - php/commitdiff
Fixed bug #52327 (base64_decode() improper handling of leading padding in strict...
authorIlia Alshanetsky <iliaa@php.net>
Fri, 26 Nov 2010 20:59:13 +0000 (20:59 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 26 Nov 2010 20:59:13 +0000 (20:59 +0000)
ext/standard/base64.c
ext/standard/tests/url/bug52327.phpt [new file with mode: 0644]

index 8e596b122108cb8e827f23b31dfb889449b9e0f6..192a08a43f9939e276c8d0bd061bca42f0bc37d2 100644 (file)
@@ -152,7 +152,7 @@ PHPAPI unsigned char *php_base64_decode_ex(const unsigned char *str, int length,
        /* run through the whole string, converting as we go */
        while ((ch = *current++) != '\0' && length-- > 0) {
                if (ch == base64_pad) {
-                       if (*current != '=' && (i % 4) == 1) {
+                       if (*current != '=' && ((i % 4) == 1 || (strict && length > 0))) {
                                efree(result);
                                return NULL;
                        }
diff --git a/ext/standard/tests/url/bug52327.phpt b/ext/standard/tests/url/bug52327.phpt
new file mode 100644 (file)
index 0000000..fb2e0fa
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Bug #52327 (base64_decode() improper handling of leading padding)
+--FILE--
+<?php
+var_dump(
+       base64_decode('=VGhl=ICc9=JyBz=eW1i=b2xz=IGFy=ZW4n=dCBh=bGxv=d2Vk=IHdo=ZXJl=IGkg=cHV0=IHRo=ZW0g=by5P'),
+       base64_decode('=VGhl=ICc9=JyBz=eW1i=b2xz=IGFy=ZW4n=dCBh=bGxv=d2Vk=IHdo=ZXJl=IGkg=cHV0=IHRo=ZW0g=by5P', true)
+);
+?>
+--EXPECT--
+string(51) "The '=' symbols aren't allowed where i put them o.O"
+bool(false)