Skip to content

Commit

Permalink
Fix #79532: sizeof off_t can be wrong
Browse files Browse the repository at this point in the history
We have to actually determine the proper `SIZEOF_OFF_T`.
Interestingly, it is `4` on Windows x64.

We also have to prevent the redefinition in pg_config.h.  The clean
solution would likely be to not include pg_config.h at all, but that's
out of scope for BC reasons for now.
  • Loading branch information
cmb69 committed Apr 29, 2020
1 parent b1b98e0 commit 67f9b0b
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 7.4.7

- FFI:
. Fixed bug #79532 (sizeof off_t can be wrong). (cmb)

?? ??? ????, PHP 7.4.6

Expand Down
1 change: 1 addition & 0 deletions build/php.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,7 @@ AC_DEFUN([PHP_CHECK_STDINT_TYPES], [
AC_CHECK_SIZEOF([long])
AC_CHECK_SIZEOF([long long])
AC_CHECK_SIZEOF([size_t])
AC_CHECK_SIZEOF([off_t])
AC_CHECK_TYPES([int8, int16, int32, int64, int8_t, int16_t, int32_t, int64_t, uint8, uint16, uint32, uint64, uint8_t, uint16_t, uint32_t, uint64_t, u_int8_t, u_int16_t, u_int32_t, u_int64_t], [], [], [
#if HAVE_STDINT_H
# include <stdint.h>
Expand Down
38 changes: 38 additions & 0 deletions ext/ffi/tests/bug79532.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--TEST--
Bug #79532 (sizeof off_t can be wrong)
--SKIPIF--
<?php
if (!extension_loaded('ffi')) die('skip ffi extension not available');
if (!extension_loaded('zend-test')) die('skip zend-test extension not available');
?>
--FILE--
<?php
require_once('utils.inc');

$header = <<<HEADER
void bug79532(off_t *array, size_t elems);
HEADER;

if (PHP_OS_FAMILY !== 'Windows') {
$ffi = FFI::cdef($header);
} else {
try {
$ffi = FFI::cdef($header, 'php_zend_test.dll');
} catch (FFI\Exception $ex) {
$ffi = FFI::cdef($header, ffi_get_php_dll_name());
}
}

$array = FFI::new("off_t[3]");
$ffi->bug79532($array, 3);
var_dump($array);
?>
--EXPECTF--
object(FFI\CData:int%d_t[3])#%d (3) {
[0]=>
int(0)
[1]=>
int(1)
[2]=>
int(2)
}
1 change: 1 addition & 0 deletions ext/pdo_pgsql/pdo_pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "php_pdo_pgsql_int.h"

#ifdef HAVE_PG_CONFIG_H
#undef SIZEOF_OFF_T
#include <pg_config.h>
#endif

Expand Down
1 change: 1 addition & 0 deletions ext/pdo_pgsql/pgsql_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "pdo/php_pdo_driver.h"
#include "pdo/php_pdo_error.h"
#include "ext/standard/file.h"
#undef SIZEOF_OFF_T
#include "pg_config.h" /* needed for PG_VERSION */
#include "php_pdo_pgsql.h"
#include "php_pdo_pgsql_int.h"
Expand Down
1 change: 1 addition & 0 deletions ext/pgsql/php_pgsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extern zend_module_entry pgsql_module_entry;
#endif

#ifdef HAVE_PG_CONFIG_H
#undef SIZEOF_OFF_T
#include <pg_config.h>
#endif

Expand Down
1 change: 1 addition & 0 deletions ext/zend_test/php_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ struct bug79096 {
};

ZEND_API struct bug79096 bug79096(void);
ZEND_API void bug79532(off_t *array, size_t elems);

#endif
8 changes: 8 additions & 0 deletions ext/zend_test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,11 @@ struct bug79096 bug79096(void)
b.b = 1;
return b;
}

void bug79532(off_t *array, size_t elems)
{
int i;
for (i = 0; i < elems; i++) {
array[i] = i;
}
}
1 change: 1 addition & 0 deletions win32/build/config.w32.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
# define SIZEOF_SIZE_T 4
# define SIZEOF_PTRDIFF_T 4
#endif
#define SIZEOF_OFF_T 4
#define HAVE_FNMATCH
#define HAVE_GLOB
#define PHP_SHLIB_SUFFIX "dll"
Expand Down

0 comments on commit 67f9b0b

Please sign in to comment.