gpt4 book ai didi

php - preg_match_all 导致 child 死亡

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:44:00 29 4
gpt4 key购买 nike

我有一个接受图像复制/粘贴的 TinyMCE 表单。输入完评论后,按“发布”,它会提交表单,解析内容并显示在屏幕对话中。

我正在尝试使用 preg_match_all 从 POSTed 变量中提取 base64 编码数据。我的大多数模式都有效,但这个导致 Apache 崩溃。

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

崩溃是无声的,我从 Apache/PHP 得到的唯一提示是 error.log 文件中的一行:

[error] child died with signal 11

我已经将它缩小到 preg_match_all 中的这种模式以及我在第二组之后有一个 * 的事实,它包含一个类定义,旨在跟随 base64 字符以引号结尾。

示例图像可在此处获得(文本文件,base64 编码): https://cloud.highpoweredhelp.com/index.php/s/hnIaFmK9vTCOmcU

我唯一能想到的是“*”太贪心了,太占内存了。但是,这有两个问题:

  1. 我将 php.ini 中的 memory_limit 从 128M 增加到 256M 但没有结果,并且
  2. 文件大小只有198K。

系统:Debian Wheezy 7.9 上的 Apache v2.2.22PHP 版本: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+/=]*) 模式将捕获每个字符,并且不会崩溃!

关于php - preg_match_all 导致 child 死亡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34185498/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com