Bug #62875 [Opn]: base64_encode broken with binary string
Edit report at https://bugs.php.net/bug.php?id=62875&edit=1
ID: 62875
User updated by: robertleglu at msn dot com
Reported by: robertleglu at msn dot com
Summary: base64_encode broken with binary string
Status: Open
Type: Bug
Package: URL related
Operating System: z/OS
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
I continue searching and i am pretty sure that the internal routines is written
with an ascii table somewhere.
I was testing my routine called portable_base64_encode on z/OS and was confused
because it seems to be wrong.
Here is the result :
str : A base64_encode : QQ== portable_base64_encode : wQ==
str : ABC base64_encode : QUJD portable_base64_encode : wcLD
But, although the built-in function may seem right and mine seems wrong,
the fact is that the binary code of 'A' 'B' and 'C' are not 65, 66 and
67, but
193, 194 and 195 in EBCDIC.
So, even for a human-readable string, the built-in routine is wrong because
base64 is intended to encode a binary flow...
Previous Comments:
------------------------------------------------------------------------
[2012-08-20 15:25:56] rasmus@php.net
reeze, it isn't really OS-specific but rather EBCDIC-specific. We have EBCDIC
hacks in a few places, but I guess nobody bothered to make base64_encode EBCDIC-
safe.
------------------------------------------------------------------------
[2012-08-20 15:23:24] reeze dot xia at gmail dot com
I can't reproduce it.
http://3v4l.org/GIL8C
It seems a OS specific bug. and I can't get a z/OS :(
------------------------------------------------------------------------
[2012-08-20 14:29:22] robertleglu at msn dot com
Description:
------------
problem occurs on z/OS 1.11 (OS of IBM mainframe) with latest version of php for
that system.
binary strings are badly encoded with base64_encode.
rewriting my own (portable) version bypass the problem.
php version : (php_cli --version)
PHP 5.1.2 (cli) (built: Sep 28 2010 16:33:24)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies
Note that z/OS works in EBCDIC, so any code that assume ascii code, ascii order
and ascii continuity is broken
Test script:
---------------
<?php
$str = chr(0x47).chr(0x49).chr(46);
echo base64_encode($str).PHP_EOL;
?>
Expected result:
----------------
R0ku
Actual result:
--------------
5fEG
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62875&edit=1
Thread (5 messages)