Commit:    d2a784baa68ea2f866ebf028064712bd12797a1e
Author:    Anatol Belski <a...@php.net>         Wed, 8 May 2013 18:58:32 +0200
Parents:   9ef017af007384215679c30a7ca72ffc9f7effa2
Branches:  master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=d2a784baa68ea2f866ebf028064712bd12797a1e

Log:
Fixed bug #64769 mbstring PHPTs crash on Windows x64

The tricky business going there in oniguruma is saving a pointer
in an int variable, passing that variable into a function and making
it a pointer again. On 64bit windows casting a pointer to a 32 bit
int will truncate that pointer. This kind of things won't work on
Windows x64.

[SNIPPET]
unsigned long ul0[2], ul1, *ul2;

ul0[0] = 42uL;
ul0[0] = 24uL;

ul1 = (unsigned long)ul0;
ul2 = (unsigned long *)ul1;

/* now it's broken, accessing ul2[0] will crash. */
[/SNIPPET]

To make it portable, ULONG_PTR should be used in this case.

In oniguruma this behaviour is to see at least in the following
codepath:

ext/mbstring/oniguruma/enc/unicode.c:10938
ext/mbstring/oniguruma/st.c:308
ext/mbstring/oniguruma/enc/unicode.c:10859

Bugs:
https://bugs.php.net/64769

Changed paths:
  M  NEWS
  M  ext/mbstring/oniguruma/oniguruma.h
  M  ext/mbstring/oniguruma/st.h


Diff:
diff --git a/NEWS b/NEWS
index 0cb524a..eeff8e7 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,9 @@ PHP                                                           
             NEWS
   . Fixed bug #64770 (stream_select() fails with pipes returned by proc_open()
     on Windows x64). (Anatol)
 
+- mbstring:
+  . Fixed bug #64769 (mbstring PHPTs crash on Windows x64). (Anatol)
+
 25 Apr 2013, PHP 5.5.0 Beta 4
 
 - Core:
diff --git a/ext/mbstring/oniguruma/oniguruma.h 
b/ext/mbstring/oniguruma/oniguruma.h
index 3b55763..bf00e20 100644
--- a/ext/mbstring/oniguruma/oniguruma.h
+++ b/ext/mbstring/oniguruma/oniguruma.h
@@ -96,8 +96,13 @@ extern "C" {
 #define UChar OnigUChar
 #endif
 
-typedef unsigned char  OnigUChar;
+#ifdef _WIN32
+# include <windows.h>
+typedef ULONG_PTR OnigCodePoint;
+#else
 typedef unsigned long  OnigCodePoint;
+#endif
+typedef unsigned char  OnigUChar;
 typedef unsigned int   OnigCtype;
 typedef unsigned int   OnigDistance;
 
diff --git a/ext/mbstring/oniguruma/st.h b/ext/mbstring/oniguruma/st.h
index da65e7f..6f93870 100644
--- a/ext/mbstring/oniguruma/st.h
+++ b/ext/mbstring/oniguruma/st.h
@@ -6,7 +6,12 @@
 
 #define ST_INCLUDED
 
+#ifdef _WIN32
+# include <windows.h>
+typedef ULONG_PTR st_data_t;
+#else
 typedef unsigned long st_data_t;
+#endif
 #define ST_DATA_T_DEFINED
 
 typedef struct st_table st_table;


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to