V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
jiangchuankyo
V2EX  ›  问与答

这种 PHP 判断漏洞 BUG 是不是无解了?

  •  
  •   jiangchuankyo · May 13, 2020 · 1336 views
    This topic created in 2182 days ago, the information mentioned may be changed or developed.
    <?php
    header("Content-type: text/html; charset=gbk");
    $a = '度和';
    if(strpos($a, '群')) {
    echo '存在';
    }else{
    echo '不存在';
    }
    ?>

    文件是 GBK 的, 判断显示存在, 这是我在写敏感词过滤时无意发现的, 这种 BUG 太严重了,

    因为度的后半个字与和的前半个字切割下来就是群字, 当然存在这种 BUG 的字是数不胜数的, 这个只是我偶然才发现的其中之一,

    同样测试, str_replace, preg_match(), strstr() 等一切与字符串沾边的函数都具有该 BUG,

    如果你的文件是 GBK 编码, 或就算是 UTF8 编码但你处理的字符串是 GBK 是也会有该 BUG, 这种底层编码 BUG 是不是无解的
    dickfu
        1
    dickfu  
       May 14, 2020
    也就是说楼主并不知道 `mb_strpos()` 这种东西的存在呗?
    jiangchuankyo
        2
    jiangchuankyo  
    OP
       May 14, 2020
    mb_strpos() 测试同样显示判断存在
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2714 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:14 · PVG 21:14 · LAX 06:14 · JFK 09:14
    ♥ Do have faith in what you're doing.