com php-src: base64_decode: fix bug #721 52 (fail on NUL bytes in strict mode): ext/standard/base64.c ext/standard/tests/strings/bug 72152.phpt
| From: | Nikita Popov | Date: | Wed, 06 Jul 2016 23:27:23 +0000 |
| Subject: | com php-src: base64_decode: fix bug #721 52 (fail on NUL bytes in strict mode): ext/standard/base64.c ext/standard/tests/strings/bug 72152.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92851@lists.php.net to get a copy of this message | ||
Commit: b9c9be13ccbf48c02ad01e19f4fce20c104a003e
Author: Lauri Kenttä <lauri.kentta@gmail.com> Wed, 25 May 2016 21:02:41 +0300
Committer: Nikita Popov <nikic@php.net> Thu, 7 Jul 2016 01:27:23 +0200
Parents: ef6f1631610c5314062336648e13a3eb76bb564c
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b9c9be13ccbf48c02ad01e19f4fce20c104a003e
Log:
base64_decode: fix bug #72152 (fail on NUL bytes in strict mode)
This added check is actually for NOT failing in NON-strict mode.
The ch == -2 check later causes the desired failure in strict mode.
Bugs:
https://bugs.php.net/72152
Changed paths:
M ext/standard/base64.c
A ext/standard/tests/strings/bug72152.phpt
Diff:
diff --git a/ext/standard/base64.c b/ext/standard/base64.c
index e8d7f04..6c890e3 100644
--- a/ext/standard/base64.c
+++ b/ext/standard/base64.c
@@ -143,7 +143,12 @@ PHPAPI zend_string *php_base64_decode_ex(const unsigned char *str, size_t
length
result = zend_string_alloc(length, 0);
/* run through the whole string, converting as we go */
- while (length-- > 0 && (ch = *current++) != '\0') {
+ while (length-- > 0) {
+ ch = *current++;
+ /* stop on null byte in non-strict mode (FIXME: is this really desired?) */
+ if (ch == 0 && !strict) {
+ break;
+ }
if (ch == base64_pad) {
/* fail if the padding character is second in a group (like V===) */
/* FIXME: why do we still allow invalid padding in other places in the middle of the string? */
diff --git a/ext/standard/tests/strings/bug72152.phpt b/ext/standard/tests/strings/bug72152.phpt
new file mode 100644
index 0000000..440a90e
--- /dev/null
+++ b/ext/standard/tests/strings/bug72152..phpt
@@ -0,0 +1,11 @@
+--TEST--
+Bug #72152 (base64_decode $strict fails to detect null byte)
+--FILE--
+<?php
+var_dump(base64_decode("\x00", true));
+var_dump(base64_decode("\x00VVVV", true));
+var_dump(base64_decode("VVVV\x00", true));
+--EXPECT--
+bool(false)
+bool(false)
+bool(false)