Bug #62875 [Opn->Wfx]: base64_encode broken with binary string
| From: | cmb@php.net | Date: | Thu, 09 Sep 2021 10:25:54 +0000 |
| Subject: | Bug #62875 [Opn->Wfx]: base64_encode broken with binary string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-236481@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62875&edit=1
ID: 62875
Updated by: cmb@php.net
Reported by: robertleglu at msn dot com
Summary: base64_encode broken with binary string
-Status: Open
+Status: Wont fix
Type: Bug
Package: URL related
Operating System: z/OS
PHP Version: Irrelevant
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
As of PHP 8.0.0, EBCDIC is no longer supported at all:
<https://github.com/php/php-src/pull/5390>.
Previous Comments:
------------------------------------------------------------------------
[2012-08-21 07:56:14] robertleglu at msn dot com
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...
------------------------------------------------------------------------
[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