]> granicus.if.org Git - php/commitdiff
Fix #79532: sizeof off_t can be wrong
authorChristoph M. Becker <cmbecker69@gmx.de>
Tue, 28 Apr 2020 16:33:19 +0000 (18:33 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 29 Apr 2020 08:40:59 +0000 (10:40 +0200)
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.

NEWS
build/php.m4
ext/ffi/tests/bug79532.phpt [new file with mode: 0644]
ext/pdo_pgsql/pdo_pgsql.c
ext/pdo_pgsql/pgsql_driver.c
ext/pgsql/php_pgsql.h
ext/zend_test/php_test.h
ext/zend_test/test.c
win32/build/config.w32.h.in

diff --git a/NEWS b/NEWS
index ba008a7ba7f7cffca93154d1a4a91649413617c3..f1312256756dfe17544e3eb8535818a29d77b83e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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
 
index 7392876478cd872340024649624a76b7c0dd2fcc..51fa37446a509759bbd4d63662d47bb7daf6ae59 100644 (file)
@@ -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>
diff --git a/ext/ffi/tests/bug79532.phpt b/ext/ffi/tests/bug79532.phpt
new file mode 100644 (file)
index 0000000..b6887dc
--- /dev/null
@@ -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)
+}
index 8d60fe420b0b0b9dfbf7b9ffd99d4d025752fe0d..8d4158198dfbeafa07737fa6dc03b4cdd59d828d 100644 (file)
@@ -29,6 +29,7 @@
 #include "php_pdo_pgsql_int.h"
 
 #ifdef HAVE_PG_CONFIG_H
+#undef SIZEOF_OFF_T
 #include <pg_config.h>
 #endif
 
index b6f008071c628d74b8bd5fb01c57aa564fc47d6f..403bfd611ae1e34d2495b2ffc53a53538115259a 100644 (file)
@@ -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"
index cecd2cc95b33e9c327f84d46c8c5183bfdf8ced0..a6c884d912b7ca5f6c3e4e62fe5a4b3b4a747250 100644 (file)
@@ -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
 
index 325484c43480580142af0b941b4d5b18cbfbaf55..da57f7efc9a0e0eb6b75b755146ceab4032b5e76 100644 (file)
@@ -38,5 +38,6 @@ struct bug79096 {
 };
 
 ZEND_API struct bug79096 bug79096(void);
+ZEND_API void bug79532(off_t *array, size_t elems);
 
 #endif
index b097a2412b9f53f20b30fa3de1a9ea5daa69812d..dfae54e880d6ca27120d9a468c6f5d199845c17a 100644 (file)
@@ -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;
+       }
+}
index 864bc882ff612cf1b6acd007410ea17f76818a6e..36a45fb76c1866ba965ddfe90b110165a47eb006 100644 (file)
 # 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"