php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: calvin at cmpct dot info
New email:
PHP Version: OS:

 

 [2021-03-12 22:19 UTC] calvin at cmpct dot info
Description:
------------
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 ffi.so (-maix64) -shared ffi.c)

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

// ffi3.php

<?php

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


Expected result:
----------------
1122334455667788
11223344


Actual result:
--------------
1122334455667788
0


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-16 21:26 UTC] cmb@php.net
-Package: ffi +Package: FFI
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 05:01:29 2024 UTC