Press "Enter" to skip to content

A Deep Dive into PCRE's Max Backtrack/Recursion Limits

Today, Tank asked about this regex:

/<script>.*?</script>/is

When the string to be matched is longer than 100014, it will not produce the correct result:

$reg = "/<script>.*?</script>/is";
$str = "<script>********</script>"; //length greater than 100014
$ret = preg_replace($reg, "", $str); //returns NULL

Does a regex impose a length limit on the string it matches?

Filed in English, PHP应用, PHP源码分析
with 0 Comment

A Possible Security Vulnerability in Nginx + PHP CGI

The usual Nginx + PHP cgi setup sets SCRIPT_FILENAME in the config file with a regex match (The PATH_INFO Problem with Nginx (PHP/fastcgi)). Today Xiaodun found a security hole in this approach.
Say you have http://www.laruence.com/fake.jpg. Craft the following URL and you can see the binary contents of fake.jpg:

http://www.laruence.com/fake.jpg/foo.php

Why does that happen?

Filed in English, PHP应用
with 0 Comment

PHP Internals — Objects (Part 1)

How PHP5 objects are actually laid out in the Zend Engine: the zval and its zend_object_value, the integer handle into the global object store, what zend_object and zend_class_entry hold, mangled property names behind public/private/protected, and the 23 standard object handlers plus magic methods.

Filed in English, PHP源码分析
with 0 Comment

Understanding the Difference Between SET NAMES and mysql(i)_set_charset

Recently my company organized a PHP secure programming training, part of which touched on MySQL's "SET NAMES" and mysql_set_charset (mysqli_set_charset):
it said to prefer mysqli_set_charset over "SET NAMES". The PHP manual mentions this too, but it never explains why.
Several friends have asked me this question lately. Why, exactly?
Enough people asked that I figured it was worth writing a post devoted to the subject.

Filed in English, MySQL/PostgreSQL, PHP源码分析
with 0 Comment