|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80857 Big endian issue with functions returning 32-bit integers on 64-bit OS
Submitted: 2021-03-12 22:19 UTC Modified: 2021-09-16 21:26 UTC
From: calvin at cmpct dot info Assigned:
Status: Open Package: FFI (PECL)
PHP Version: 8.0.3 OS: IBM i 7.2
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-03-12 22:19 UTC] calvin at cmpct dot info
On a big endian system (in my case, IBM i PASE), the FFI extension, at least for 32-bit integers returned (but likely other types/mechanisms as well from a skimming of the source), will return 0. This is seemingly because the result is stored in a 64-bit word, but FFI accesses it as if it was a 32-bit value. This works on little-endian, but returns the empty part of the word on big-endian.

The actual result is from an IBM i PASE system (ppc64be), while the expected result is from an amd64 Fedora system.

Test script:
// ffi.c (gcc -o (-maix64) -shared ffi.c)

long long problem(void)
        return 0x1122334455667788;
int problem32(void)
        return 0x11223344;

// ffi3.php


$ffi = FFI::cdef("long long problem(); int problem32();", "./");
echo dechex($ffi->problem()) . "\n";
echo dechex($ffi->problem32()) . "\n";

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-16 21:26 UTC]
-Package: ffi +Package: FFI
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 10:01:34 2024 UTC