我有一个Tinymce表单,可以接受图像的复制/粘贴。当你完成评论后,你按“post”,它就会提交表单,内容会被解析,并显示在屏幕上的对话中。
我试图使用preg_match_all从发布的vars中提取base64编码的数据。我的大多数模式都可以工作,但这一个模式会导致apache崩溃。

<img src="data:image/(png|PNG|gif|GIF|jpg|JPG|jpeg|JPEG);base64,([a-zA-Z0-9+/=])*

崩溃是无声的,我从apache/php得到的唯一提示是error.log文件中的一行:
[错误]孩子死于信号11
我把它缩小到preg_match_all中的这个模式,并且在第二个组后面有一个*这个事实,这个组由一个类定义组成,该类定义设计为在base64字符之后以引号结尾。
此处提供示例图像(文本文件,base64编码):
https://cloud.highpoweredhelp.com/index.php/s/hnIaFmK9vTCOmcU
我唯一能想到的是,“*”太贪心了,消耗了太多的内存。但是,有两个问题:
我将php.in i中的内存限制从128m增加到256m,但没有结果,并且
文件大小只有198K。
系统:
ApacheV2.2.22关于Debian喘息7.9
php版本:5.6.16使用以下配置从源代码编译:
./configure --with-config-file-path=/etc/php5/apache2 \
--with-pear=/usr/share/php \
--with-bz2 \
--with-curl \
--with-gd \
--enable-calendar \
--enable-mbstring \
--enable-bcmath \
--enable-sockets \
--with-libxml-dir \
--with-mysqli \
--with-mysql \
--with-openssl \
--with-regex=php \
--with-readline \
--with-zlib \
--with-apxs2=/usr/bin/apxs2 \
--enable-soap \
--with-freetype-dir=/usr/include/freetype2/ \
--with-freetype \
--with-mcrypt=/usr/src/mcrypt-2.6.8 \
--with-jpeg-dir=/usr/lib/x86_64-linux-gnu/ \
--with-png-dir=/usr/lib/x86_64-linux-gnu/

最佳答案

你真的打算([a-zA-Z0-9+/=]*)而不是([a-zA-Z0-9+/=])*
后一种模式只能得到base64序列的最后一个字符,但似乎会很快导致分割错误。我可以用一个相对较短的字符串使一个命令行应用程序崩溃,其模式如下:

#this segfaulted for me, a shorter string did succeed
$str='<img src="data:image/png;base64,'.str_repeat('0123456789',1000);
if (preg_match('{<img src="data:image/(png|PNG|gif|GIF|jpg|JPG|jpeg|JPEG);base64,([a-zA-Z0-9+/=])*}', $str, $match)){
        print "matched";
}

([a-zA-Z0-9+/=]*)模式将捕获每个字符,并且不会崩溃!

09-03 19:44
查看更多