php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79532 sizeof off_t can be wrong
Submitted: 2020-04-28 08:10 UTC Modified: 2020-04-29 08:33 UTC
From: cmb@php.net Assigned: cmb (profile)
Status: Closed Package: ffi (PECL)
PHP Version: 7.4Git-2020-04-28 (Git) OS: some (e.g.Windows)
Private report: No CVE-ID: None
 [2020-04-28 08:10 UTC] cmb@php.net
Description:
------------
The sizeof off_t is determined via the C macro SIZEOF_OFF_T which
is not defined.  This causes wrong handling of off_t values on
some architectures, e.g. x86.

This issue has been found by girgias@php.net.


Test script:
---------------
// C code

void fill_array(off_t *array, size_t elems)
{
	int i;
	for (i = 0; i < elems; i++) {
		array[i] = i;
	}
}


<?php
$ffi = FFI::cdef('void fill_array(off_t *array, size_t elems);');
$array = FFI::new("off_t[3]");
$ffi->fill_array($array, 3);
var_dump($array);
?>


Expected result:
----------------
object(FFI\CData:int64_t[3])#2 (3) {
  [0]=>
  int(0)
  [1]=>
  int(1)
  [2]=>
  int(2)
}


Actual result:
--------------
object(FFI\CData:int32_t[3])#2 (3) {
  [0]=>
  int(0)
  [1]=>
  int(1)
  [2]=>
  int(2)
}

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-28 08:12 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-04-28 08:12 UTC] cmb@php.net
Oops, I screwed up the expected and actual results.  Should have
been:

Expected result:
----------------
object(FFI\CData:int32_t[3])#2 (3) {
  [0]=>
  int(0)
  [1]=>
  int(1)
  [2]=>
  int(2)
}

Actual result:
--------------
object(FFI\CData:int64_t[3])#2 (3) {
  [0]=>
  int(0)
  [1]=>
  int(2)
  [2]=>
  int(0)
}
 [2020-04-28 08:25 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #79532: sizeof off_t can be wrong
On GitHub:  https://github.com/php/php-src/pull/5482
Patch:      https://github.com/php/php-src/pull/5482.patch
 [2020-04-29 08:33 UTC] cmb@php.net
-Operating System: x86 (and maybe others) +Operating System: some (e.g.Windows)
 [2020-04-29 08:45 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=67f9b0b754654e76ef8d5b5539fb520541092950
Log: Fix #79532: sizeof off_t can be wrong
 [2020-04-29 08:45 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Oct 20 08:01:24 2020 UTC