|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62875 base64_encode broken with binary string
Submitted: 2012-08-20 14:29 UTC Modified: 2021-09-09 10:25 UTC
Avg. Score:4.0 ± 1.0
Reproduced:0 of 0 (0.0%)
From: robertleglu at msn dot com Assigned: cmb (profile)
Status: Wont fix Package: URL related
PHP Version: Irrelevant OS: z/OS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
26 - 19 = ?
Subscribe to this entry?

 [2012-08-20 14:29 UTC] robertleglu at msn dot com
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:
$str = chr(0x47).chr(0x49).chr(46);
echo base64_encode($str).PHP_EOL;

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-20 15:23 UTC] reeze dot xia at gmail dot com
I can't reproduce it.

It seems a OS specific bug. and I can't get a z/OS :(
 [2012-08-20 15:25 UTC]
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-
 [2012-08-21 07:56 UTC] 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...
 [2021-09-09 10:25 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-09-09 10:25 UTC]
As of PHP 8.0.0, EBCDIC is no longer supported at all:
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 14 02:01:28 2024 UTC