Skip to content

Commit 67f9b0b

Browse files
committed
Fix #79532: sizeof off_t can be wrong
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.
1 parent b1b98e0 commit 67f9b0b

File tree

9 files changed

+56
-0
lines changed

9 files changed

+56
-0
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3+
?? ??? ????, PHP 7.4.7
4+
5+
- FFI:
6+
. Fixed bug #79532 (sizeof off_t can be wrong). (cmb)
37

48
?? ??? ????, PHP 7.4.6
59

build/php.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2416,6 +2416,7 @@ AC_DEFUN([PHP_CHECK_STDINT_TYPES], [
24162416
AC_CHECK_SIZEOF([long])
24172417
AC_CHECK_SIZEOF([long long])
24182418
AC_CHECK_SIZEOF([size_t])
2419+
AC_CHECK_SIZEOF([off_t])
24192420
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], [], [], [
24202421
#if HAVE_STDINT_H
24212422
# include <stdint.h>

ext/ffi/tests/bug79532.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Bug #79532 (sizeof off_t can be wrong)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('ffi')) die('skip ffi extension not available');
6+
if (!extension_loaded('zend-test')) die('skip zend-test extension not available');
7+
?>
8+
--FILE--
9+
<?php
10+
require_once('utils.inc');
11+
12+
$header = <<<HEADER
13+
void bug79532(off_t *array, size_t elems);
14+
HEADER;
15+
16+
if (PHP_OS_FAMILY !== 'Windows') {
17+
$ffi = FFI::cdef($header);
18+
} else {
19+
try {
20+
$ffi = FFI::cdef($header, 'php_zend_test.dll');
21+
} catch (FFI\Exception $ex) {
22+
$ffi = FFI::cdef($header, ffi_get_php_dll_name());
23+
}
24+
}
25+
26+
$array = FFI::new("off_t[3]");
27+
$ffi->bug79532($array, 3);
28+
var_dump($array);
29+
?>
30+
--EXPECTF--
31+
object(FFI\CData:int%d_t[3])#%d (3) {
32+
[0]=>
33+
int(0)
34+
[1]=>
35+
int(1)
36+
[2]=>
37+
int(2)
38+
}

ext/pdo_pgsql/pdo_pgsql.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "php_pdo_pgsql_int.h"
3030

3131
#ifdef HAVE_PG_CONFIG_H
32+
#undef SIZEOF_OFF_T
3233
#include <pg_config.h>
3334
#endif
3435

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "pdo/php_pdo_driver.h"
3232
#include "pdo/php_pdo_error.h"
3333
#include "ext/standard/file.h"
34+
#undef SIZEOF_OFF_T
3435
#include "pg_config.h" /* needed for PG_VERSION */
3536
#include "php_pdo_pgsql.h"
3637
#include "php_pdo_pgsql_int.h"

ext/pgsql/php_pgsql.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ extern zend_module_entry pgsql_module_entry;
5151
#endif
5252

5353
#ifdef HAVE_PG_CONFIG_H
54+
#undef SIZEOF_OFF_T
5455
#include <pg_config.h>
5556
#endif
5657

ext/zend_test/php_test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ struct bug79096 {
3838
};
3939

4040
ZEND_API struct bug79096 bug79096(void);
41+
ZEND_API void bug79532(off_t *array, size_t elems);
4142

4243
#endif

ext/zend_test/test.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,11 @@ struct bug79096 bug79096(void)
328328
b.b = 1;
329329
return b;
330330
}
331+
332+
void bug79532(off_t *array, size_t elems)
333+
{
334+
int i;
335+
for (i = 0; i < elems; i++) {
336+
array[i] = i;
337+
}
338+
}

win32/build/config.w32.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
# define SIZEOF_SIZE_T 4
102102
# define SIZEOF_PTRDIFF_T 4
103103
#endif
104+
#define SIZEOF_OFF_T 4
104105
#define HAVE_FNMATCH
105106
#define HAVE_GLOB
106107
#define PHP_SHLIB_SUFFIX "dll"

0 commit comments

Comments
 (0)