iliaa                                    Mon, 12 Sep 2011 17:20:24 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=316560

Log:
Fixed bug #55273 (base64_decode() with strict rejects whitespace after pad)

Bug: https://bugs.php.net/55273 (Open) base64_decode with strict rejects 
whitespace after pad
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/standard/base64.c
    A   php/php-src/branches/PHP_5_3/ext/standard/tests/url/bug55273.phpt
    U   php/php-src/branches/PHP_5_4/ext/standard/base64.c
    A   php/php-src/branches/PHP_5_4/ext/standard/tests/url/bug55273.phpt
    U   php/php-src/trunk/ext/standard/base64.c
    A   php/php-src/trunk/ext/standard/tests/url/bug55273.phpt

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2011-09-12 17:09:58 UTC (rev 316559)
+++ php/php-src/branches/PHP_5_3/NEWS   2011-09-12 17:20:24 UTC (rev 316560)
@@ -12,6 +12,8 @@
     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

Modified: php/php-src/branches/PHP_5_3/ext/standard/base64.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/base64.c  2011-09-12 17:09:58 UTC 
(rev 316559)
+++ php/php-src/branches/PHP_5_3/ext/standard/base64.c  2011-09-12 17:20:24 UTC 
(rev 316560)
@@ -153,6 +153,14 @@
        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;
                        }

Added: php/php-src/branches/PHP_5_3/ext/standard/tests/url/bug55273.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/standard/tests/url/bug55273.phpt           
                (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/standard/tests/url/bug55273.phpt   
2011-09-12 17:20:24 UTC (rev 316560)
@@ -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"

Modified: php/php-src/branches/PHP_5_4/ext/standard/base64.c
===================================================================
--- php/php-src/branches/PHP_5_4/ext/standard/base64.c  2011-09-12 17:09:58 UTC 
(rev 316559)
+++ php/php-src/branches/PHP_5_4/ext/standard/base64.c  2011-09-12 17:20:24 UTC 
(rev 316560)
@@ -153,6 +153,14 @@
        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;
                        }

Added: php/php-src/branches/PHP_5_4/ext/standard/tests/url/bug55273.phpt
===================================================================
--- php/php-src/branches/PHP_5_4/ext/standard/tests/url/bug55273.phpt           
                (rev 0)
+++ php/php-src/branches/PHP_5_4/ext/standard/tests/url/bug55273.phpt   
2011-09-12 17:20:24 UTC (rev 316560)
@@ -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"

Modified: php/php-src/trunk/ext/standard/base64.c
===================================================================
--- php/php-src/trunk/ext/standard/base64.c     2011-09-12 17:09:58 UTC (rev 
316559)
+++ php/php-src/trunk/ext/standard/base64.c     2011-09-12 17:20:24 UTC (rev 
316560)
@@ -153,6 +153,14 @@
        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;
                        }

Added: php/php-src/trunk/ext/standard/tests/url/bug55273.phpt
===================================================================
--- php/php-src/trunk/ext/standard/tests/url/bug55273.phpt                      
        (rev 0)
+++ php/php-src/trunk/ext/standard/tests/url/bug55273.phpt      2011-09-12 
17:20:24 UTC (rev 316560)
@@ -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"

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to