|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77284 base64 broken on FreeBSD
Submitted: 2018-12-11 20:44 UTC Modified: 2019-01-02 12:02 UTC
Avg. Score:4.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: anubas at hotmail dot com Assigned: laruence (profile)
Status: Verified Package: *URL Functions
PHP Version: 7.3.0 OS: FreeBSD 11.2-RELEASE-p5
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-12-11 20:44 UTC] anubas at hotmail dot com
Problem: $x != $z in the test script below.

Test script:

$x = 'This is a string';
$y = base64_encode($x);
$z = base64_decode($y);

if ($x != $z) {
    print 'base64 encoding/decoding broken';

Expected result:
$x == $z

Actual result:
$x != $z


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-11 20:53 UTC]
-Status: Open +Status: Feedback
 [2018-12-11 20:53 UTC]
I can't reproduce the bug:

This is going to be a problem either with your system, or some other problem we can't help with.

Please feel free to update this with a reproducible case.
 [2018-12-11 21:17 UTC] anubas at hotmail dot com
This worked fine on PHP 7.2.12 on the same server. The only thing that has changed is the version of PHP that I am using.
 [2018-12-11 21:28 UTC] anubas at hotmail dot com
The following code:


$x = 'This is a string';
$y = base64_encode($x);
$z = base64_decode($y);

var_dump($x) . '<br />';
var_dump($y) . '<br />';
var_dump($z) . '<br />';


string(16) "This is a string"
string(-6072743447921604100) "

2018/12/11 13:24:05 [error] 91715#100408: *63 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted (tried to allocate 12374000625787949056 bytes) in [FILE] on line 8" while reading response header from upstream, client: [IP], server: [SERVER], request: "GET /[FILE] HTTP/1.0", upstream: "fastcgi://", host: "[SERVER]"

It appears the output from base64_encode() is invalid.
 [2018-12-11 21:41 UTC]
Base64 encoding has SIMD based implementations in 7.3, so this issue might be architecture dependent. Can you please tell me which SIMD extensions your CPU supports? In particular AVX2 and SSSE3 support would be relevant.
 [2018-12-11 21:53 UTC] anubas at hotmail dot com
I pulled the following out of the system dmesg output:

CPU: Intel(R) Xeon(R) CPU E5-2630 v2 @ 2.60GHz (2600.00-MHz K8-class CPU)
  Origin="GenuineIntel"  Id=0x306e4  Family=0x6  Model=0x3e  Stepping=4
  AMD Features=0x28100800<SYSCALL,NX,RDTSCP,LM>
  AMD Features2=0x1<LAHF>
  Structured Extended Features=0x283<FSGSBASE,TSCADJ,SMEP,ERMS>
  TSC: P-state invariant
 [2018-12-11 22:11 UTC]
-Status: Feedback +Status: Open -Assigned To: +Assigned To: laruence
 [2018-12-11 22:11 UTC]
Thanks, that should put you on the SSSE3 implementation. I just tried to force it locally, and it's working fine for me.

Not sure what could be the issue here, maybe laruence has an idea?
 [2018-12-11 22:12 UTC]
Also bug #77279 looks very related. In both cases we have a SIMD optimized function with FreeBSD as the operating system. Likely the same root cause.
 [2018-12-12 09:52 UTC] sjon at hortensius dot net
This can be reproduced pretty quickly in a qemu-vm - I downloaded, uncompressed and logged in with root and ran:

# portsnap fetch extract && cd /usr/ports/lang/php73 && make install
 (select debug build, accept defaults for the rest

This will get you a debug php73 build which shows the same behavior
 [2018-12-14 13:00 UTC]
-Status: Assigned +Status: Verified
 [2018-12-14 13:00 UTC]
I can reproduce this issue on an AMD 64 supporting SSSE3, but not
AVX2, running a Vagrant bento/freebsd-11.2[1].
resolve_base64_encode() returns php_base64_encode_ssse3()[2], but
setting a breakpoint for this function is somehow ignored.

[1] <>
[2] <>
 [2018-12-14 14:28 UTC]
Might be relevant:

    $ cc -v
    FreeBSD clang version 6.0.0 (tags/RELEASE_600/final 326565) (based on LLVM 6.0.0)
 [2018-12-14 18:56 UTC]
-Summary: base64 +Summary: base64 broken on FreeBSD
 [2018-12-14 23:33 UTC] anubas at hotmail dot com
Possible work-around: Upgrade to FreeBSD 12.0.

I used freebsd-update to upgrade the same server to FreeBSD 12.0 and re-installed the same PHP73 package. Everything works as expected.
 [2019-01-02 12:02 UTC]
I went ahead and disabled the use of ifuncs on FreeBSD:

We can reenable or restrict this check once we know the exact cause.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 23 12:01:28 2024 UTC