]> granicus.if.org Git - php/commitdiff
Fixed bug #51250 (iconv_mime_decode() does not ignore malformed Q-encoded words)
authorIlia Alshanetsky <iliaa@php.net>
Wed, 1 Dec 2010 14:03:36 +0000 (14:03 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 1 Dec 2010 14:03:36 +0000 (14:03 +0000)
NEWS
ext/iconv/iconv.c
ext/iconv/tests/bug51250.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 06447cd5dad2c64ad9d40c018756ae80c7932bea..eb51f452018ac516bafd8ee469610cf99ab097fc 100644 (file)
--- a/NEWS
+++ b/NEWS
 - Hash extension:
   . Fixed bug #51003 (unaligned memory access in ext/hash/hash_tiger.c).
     (Mike, Ilia)
+
+- Iconv extension:
+  . Fixed bug #51250 (iconv_mime_decode() does not ignore malformed Q-encoded 
+    words). (Ilia)
     
 - Intl extension:
   . Fixed crashes on invalid parameters in intl extension. (Stas, Maksymilian
index b1a9c0dd0ec0bf6e921eaef0ea3145a321e3d52f..bb977d9761aa489b6c5668971d57067dde84fce2 100644 (file)
@@ -1698,10 +1698,10 @@ static php_iconv_err_t _php_iconv_mime_decode(smart_str *pretval, const char *st
                                                        if ((mode & PHP_ICONV_MIME_DECODE_CONTINUE_ON_ERROR)) {
                                                                /* pass the entire chunk through the converter */
                                                                err = _php_iconv_appendl(pretval, encoded_word, (size_t)(p1 - encoded_word), cd_pl); 
+                                                               encoded_word = NULL;
                                                                if (err != PHP_ICONV_ERR_SUCCESS) {
-                                                                       goto out;
+                                                                       break;
                                                                }
-                                                               encoded_word = NULL;
                                                        } else {
                                                                goto out;
                                                        }
diff --git a/ext/iconv/tests/bug51250.phpt b/ext/iconv/tests/bug51250.phpt
new file mode 100644 (file)
index 0000000..fd2e53b
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+Bug #51250 (iconv_mime_decode() does not ignore malformed Q-encoded words)
+--SKIPIF--
+<?php extension_loaded('iconv') or die('skip iconv extension is not available'); ?>
+--FILE--
+<?php
+$m = ICONV_MIME_DECODE_CONTINUE_ON_ERROR;
+
+var_dump(iconv_mime_decode("Legal encoded-word: =?utf-8?B?Kg==?= .", $m));
+var_dump(iconv_mime_decode("Legal encoded-word: =?utf-8?Q?*?= .", $m));
+var_dump(iconv_mime_decode("Illegal encoded-word: =?utf-8?B?".chr(0xA1)."?= .", $m));
+var_dump(iconv_mime_decode("Illegal encoded-word: =?utf-8?Q?".chr(0xA1)."?= .", $m));
+
+var_dump(iconv_mime_decode("Legal encoded-word: =?utf-8?B?Kg==?= ."));
+var_dump(iconv_mime_decode("Legal encoded-word: =?utf-8?Q?*?= ."));
+var_dump(iconv_mime_decode("Illegal encoded-word: =?utf-8?B?".chr(0xA1)."?= ."));
+var_dump(iconv_mime_decode("Illegal encoded-word: =?utf-8?Q?".chr(0xA1)."?= ."));
+?>
+--EXPECTF--
+string(23) "Legal encoded-word: * ."
+string(23) "Legal encoded-word: * ."
+string(24) "Illegal encoded-word:  ."
+string(23) "Illegal encoded-word: ."
+string(23) "Legal encoded-word: * ."
+string(23) "Legal encoded-word: * ."
+string(24) "Illegal encoded-word:  ."
+
+Notice: iconv_mime_decode(): Detected an illegal character in input string in %s on line %d
+bool(false)