php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18706 Bug in imap_utf7_decode()
Submitted: 2002-08-02 09:51 UTC Modified: 2002-08-02 10:08 UTC
From: gamid at isayev dot net Assigned:
Status: Not a bug Package: IMAP related
PHP Version: 4.2.2 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gamid at isayev dot net
New email:
PHP Version: OS:

 

 [2002-08-02 09:51 UTC] gamid at isayev dot net
Function imap_utf7_decode() in PHP v4.2.2 has bug when IMAP folder name has non ASCII characters.
Script 'test_utf7.php3' is attached to this posting to illustrate this bug.

According PHP documentation imap_utf7_decode() returns "the decoded 8bit data", but documentation says nothing about encoding of returned "8bit data". When I try decode folder with name 'test&AN9ZJw-', imap_utf7_decode() returns following string:

0x74, 0x65, 0x73, 0x74, 0x00, 0xDF, 0x59, 0x27

It looks as UTF-16 (UCS-2) string with missed '0x00' for ASCII characters. If I'm right and imap_utf7_decode() returns UTF-16 string, this string should be represented as:

0x00, 0x74, 0x00, 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0xDF, 0x59, 0x27

To fix this this problem I wrote patch for ext/imap/php_imap.c and attache it to this posting.

Best regards,
Gamid Isayev

--- test_utf7.php3 ------------------------------------
<HTML>
<HEAD>
<TITLE>Test UTF7</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;charset=utf-8">
</HEAD>
<BODY>
<?
$folder = 'test&AN9ZJw-';
echo "folder (modified UTF-7): $folder<BR><BR>\n";

echo "<strong>mb_convert_encoding test</strong><BR>\n";
$test = $folder;
$test = mb_convert_encoding($test, "UTF-8", "UTF7-IMAP");
echo "  folder decoded: [$test]<BR>\n";
$test = mb_convert_encoding($test, "UTF7-IMAP", "UTF-8");
echo "encoded again: [", $test, "]<BR>\n";
$test = mb_convert_encoding($test, "UTF-8", "UTF7-IMAP");
echo "decoded again: [", $test, "]<BR><BR>\n";

echo "<strong>imap_utf7_decode test</strong><BR>\n";
$test = $folder;
$test = imap_utf7_decode($test);
echo "folder decoded: [", $test, "]<BR>\n";
$test = imap_utf7_encode($test);
echo "encoded again: [", $test, "]<BR>\n";
$test = imap_utf7_decode($test);
echo "decoded again: [", $test, "]<BR><BR>\n";
?>
</BODY>
</HTML>
--- end of test_utf7.php3 -----------------------------


--- ext/imap/php_imap.c -------------------------------

--- php_imap.c  Mon Jul 29 15:17:45 2002
+++ php_imap.c  Mon Jul 29 15:18:27 2002
@@ -2215,14 +2215,14 @@
                                php_error(E_WARNING, "imap_utf7_decode:
Invalid modified UTF-7 character: `%c'", *inp);
                                RETURN_FALSE;
                        } else if (*inp != '&') {
-                               outlen++;
+                               outlen += 2;
                        } else if (inp + 1 == endp) {
                                php_error(E_WARNING, "imap_utf7_decode:
Unexpected end of string");
                                RETURN_FALSE;
                        } else if (inp[1] != '-') {
                                state = ST_DECODE0;
                        } else {
-                               outlen++;
+                               outlen += 2;
                                inp++;
                        }
                } else if (*inp == '-') {
@@ -2272,8 +2272,11 @@
                        if (*inp == '&' && inp[1] != '-') {
                                state = ST_DECODE0;
                        }
-                       else if ((*outp++ = *inp) == '&') {
-                               inp++;
+                       else {
+                               *outp++ = 0x00;
+                               if ((*outp++ = *inp) == '&') {
+                                       inp++;
+                               }
                        }
                }
                else if (*inp == '-') {

--- end of ext/imap/php_imap.c ------------------------

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-02 10:07 UTC] kalowsky@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the original bug instead.

Thank you for your interest in PHP.
 [2002-08-02 10:08 UTC] kalowsky@php.net
same information at bug #15630
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Oct 11 21:01:27 2024 UTC