ZF-7413: strpos() operations on objects cause segfaults


It has come to my attention that Zend_Date() causes a segfault when you pass another Zend_Date object to its constructor. After some debugging I realized that this segfault is caused by Zend_Locale calling strpos() on that Zend_Date object in _prepareLocale().

I realize that this is probably really a PHP bug, but it seems cleaner if _prepareLocale() casts $locale to a string first before performing any string operations on it.

I was able to reproduce this by executing the following command:

php -r 'require_once "Zend/Date.php"; $x = new Zend_Date(); $y = new Zend_Date($x);'

Note that I'm only able to reproduce this problem on one out of three servers I've tested this on. I was able to reproduce it under 32-bit Debian Linux 5.0. I was not able to reproduce it under 64-bit Debian Linux 4.0 or 5.0.

I am attaching a patch that will fix the segmentation fault by casting $locale to a string at an earlier point.


Which PHP release are you using on Debian ?

5.2.9 on all three servers that I've tested. The PHP packages were provided by (the server that produced the segfault had the 5.2.9-0.dotdeb.2 packages installed).

This seems to be the related PHP bug:

The reason of this segfault seem to be the huge memory footprint used when initiating date objects.

Some performance increasements have been implemented which prevent that this error occurs in this place.

Still, ZF is not able to solve a PHP internal error. The given code should have worked even with the used memory.

Understood. But wouldn't it be cleaner to move the string cast up a few lines anyway? The workaround seems easy and clean.