php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43314 iconv_mime_encode(), broken Q scheme
Submitted: 2007-11-16 16:23 UTC Modified: 2010-03-02 10:24 UTC
Votes:16
Avg. Score:4.7 ± 0.6
Reproduced:16 of 16 (100.0%)
Same Version:3 (18.8%)
Same OS:5 (31.2%)
From: wiela at centras dot lt Assigned: rasmus
Status: Closed Package: ICONV related
PHP Version: 5.2.5 OS: Windows XP HE
Private report: No CVE-ID:
 [2007-11-16 16:23 UTC] wiela at centras dot lt

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-01 14:10 UTC] d_kelsey at uk dot ibm dot com
I encountered a similar problem with another utf-8 string, and although this may not be the best way to fix it, this change provides a workaround.

in iconv.c (line 1281 in php5.2.5) the line
out_size -= ((nbytes_required - (char_cnt - 2)) + 1) / (3 - 1);

should be changed to
out_size -= ((nbytes_required - (char_cnt - 2)) + 1) / 3;

It looks like the code attempts to determine how many characters would fit into output buffer when converted (given that it has gone over the limit), but it assumes that on average each character uses 2 bytes (ie an even mixture of encoded and printable characters). A lot of strings will be greater than this and out_size will be set to a very large positive number (as it subtracts a larger number from out_size and being unsigned will result in a large positive number).
The workaround is to take the worst case scenario and assume all characters generated 3 bytes (ie all encoded).
 [2009-01-09 14:38 UTC] om at viazenetti dot de
Hm, is this bugged fixed in newer versions? Currently we are using version 5.2.6 and the error still occures.
 [2009-11-28 22:18 UTC] dennispopel at gmail dot com
Same on Vista/PHP5.3.0
 [2010-03-02 01:34 UTC] rasmus@php.net
-Status: No Feedback +Status: Closed
 [2010-03-02 01:34 UTC] rasmus@php.net
Fixed in SVN
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 24 20:02:09 2014 UTC