#43314 [Com]: iconv_mime_encode(), broken Q scheme

2009-11-28 Thread dennispopel at gmail dot com
 ID:   43314
 Comment by:   dennispopel at gmail dot com
 Reported By:  wiela at centras dot lt
 Status:   No Feedback
 Bug Type: ICONV related
 Operating System: Windows XP HE
 PHP Version:  5.2.5
 New Comment:

Same on Vista/PHP5.3.0


Previous Comments:


[2009-01-09 14:38:50] 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.



[2008-11-04 01:00:01] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to Open.



[2008-10-27 12:56:37] j...@php.net

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/





[2008-02-01 14:10:33] 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).



[2007-11-16 16:23:17] wiela at centras dot lt

Description:

iconv_mime_encode(),'Q' encoding scheme isn't reliable and 
sometimes (for particular character and/or string length combination?)
returns: Notice: iconv_mime_encode(): Unknown error (7) in ...
*without any result*. 

This also applies to earlier php versions (tested with php 5.2.1).



Reproduce code:
---
$preferences = array(
input-charset = UTF-8,
output-charset = UTF-8,
line-length = 76,
line-break-chars = \n,
scheme = Q
);

// $str1 results error, it's utf-8 string, its base64_encode() is: 
//'xIXEjcSZxJfEr8WhxbPFviDEr8SZxI3FocWzxJnEr8SFIMSNxJnFs8SFxaHFs8Wr'
$str1 = #261;#269;#281;#279;#303;š#371;ž
#303;#281;#269;š#371;#281;#303;#261;
#269;#281;#371;#261;š#371;#363;; 

// $str2 doesn't result error, although it's only one character
// shorter. It's utf-8 string, its base64_encode() is: 
//'xIXEjcSZxJfEr8WhxbPFviDEr8SZxI3FocWzxJnEr8SFIMSNxJnFs8SFxaHFsw=='
$str2 = #261;#269;#281;#279;#303;š#371;ž
#303;#281;#269;š#371;#281;#303;#261;
#269;#281;#371;#261;š#371;;

echo iconv_mime_encode(Subject, $str1, $preferences);
echo iconv_mime_encode(Subject, $str2, $preferences);


Expected result:

Well, at least any (*some*) result is expected, without any 
errors and warnings. 

For $str1 is expected:
Subject: =?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3?=
 =?UTF-8?Q?=C5=BE=20=C4=AF=C4=99=C4=8D=C5=A1=C5=B3=C4=99=C4=AF?=
 =?UTF-8?Q?=C4=85=20=C4=8D=C4=99=C5=B3=C4=85=C5=A1=C5=B3=C5=AB?=

For $str2 is expected:
Subject: =?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3?=
 =?UTF-8?Q?=C5=BE=20=C4=AF=C4=99=C4=8D=C5=A1=C5=B3=C4=99=C4=AF?=
 =?UTF-8?Q?=C4=85=20=C4=8D=C4=99=C5=B3=C4=85=C5=A1=C5=B3?=

Actual result:
--
For $str1: 
FALSE with Notice: iconv_mime_encode(): Unknown error (7) in ...


For $str2:
Subject: =?UTF-8?Q?=C4=85=C4=8D=C4=99=C4=97=C4=AF=C5=A1=C5=B3?=
 =?UTF-8?Q?=C5=BE=20=C4=AF=C4=99=C4=8D=C5=A1=C5=B3=C4=99=C4=AF?=
 =?UTF-8?Q?=C4=85=20=C4=8D=C4=99=C5=B3=C4=85=C5=A1=C5=B3?=





-- 
Edit this bug report at http://bugs.php.net/?id=43314edit=1



Bug #16045: count($array) logical error

2002-03-13 Thread dennispopel

From: [EMAIL PROTECTED]
Operating system: All
PHP version:  4.1.1
PHP Bug Type: *General Issues
Bug description:  count($array) logical error

Hello,

Funny logical error:

if we have a simple variable, say
$x = 1

then
count($x) == 1, which is natural (I don't think so)

And if we have an array
$x[0] = 1;
count($x) == 1,

but after
UnSet($x[0])

we still have
count($x) = 1!

This leads to a very special kind of logical errors which are really hard
to track.

My suggestion:
either: introduce explicit type system (with unions, structs and arrays
;)
or: disable count on variables
-- 
Edit bug report at http://bugs.php.net/?id=16045edit=1
-- 
Fixed in CVS:http://bugs.php.net/fix.php?id=16045r=fixedcvs
Fixed in release:http://bugs.php.net/fix.php?id=16045r=alreadyfixed
Need backtrace:  http://bugs.php.net/fix.php?id=16045r=needtrace
Try newer version:   http://bugs.php.net/fix.php?id=16045r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=16045r=support
Expected behavior:   http://bugs.php.net/fix.php?id=16045r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=16045r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=16045r=submittedtwice