php / php-src

The PHP Interpreter
https://www.php.net
Other
38.15k stars 7.74k forks source link

Segmentation fault when unicode characters are used in readline prompt #8968

Closed Chi-teck closed 2 years ago

Chi-teck commented 2 years ago

Description

<?php

setlocale(LC_ALL, 'C');
readline('➤');

PHP Version

PHP 8.1.7

Operating System

Debian

damianwadley commented 2 years ago

With the non-debug PHP 7.4 I have on hand,

(gdb) bt
#0  0x00007ffff3c846e5 in ?? () from /usr/lib/x86_64-linux-gnu/libedit.so.2
#1  0x00007ffff3c858db in ?? () from /usr/lib/x86_64-linux-gnu/libedit.so.2
#2  0x00007ffff3c84e57 in ?? () from /usr/lib/x86_64-linux-gnu/libedit.so.2
#3  0x00007ffff3c85258 in el_wgets () from /usr/lib/x86_64-linux-gnu/libedit.so.2
#4  0x00007ffff3c7fd63 in el_gets () from /usr/lib/x86_64-linux-gnu/libedit.so.2
#5  0x00007ffff3c93486 in readline () from /usr/lib/x86_64-linux-gnu/libedit.so.2
#6  0x00007ffff3cb0762 in ?? () from /usr/lib/php/20190902/readline.so

Searching around, it seems there might be some issues with libedit - doesn't seem like the bug is with PHP itself: https://bugs.mysql.com/bug.php?id=89359 https://github.com/racket/racket/issues/3223

See also: https://bugs.php.net/bug.php?id=81280 https://bugs.php.net/bug.php?id=76989

cmb69 commented 2 years ago

Are you using libreadline or libeditline? Which version? See READLINE_LIB and the phpinfo() output.

Chi-teck commented 2 years ago

Readline library => EditLine wrapper

cmb69 commented 2 years ago

Thank you! While I cannot reproduce a segfault when building against libreadline-dev, I can when building against libedit-dev (3.1-20181209-1). As @damianwadley already said, this doesn't appear to be a PHP issue, though, but rather an issue with libedit.

krakjoe commented 2 years ago

Prior conversations:

This issue is (I think) fixed in 8.1 by 7635.

cmb69 commented 2 years ago

Well, the issue is not fixed if you explicitly set the C locale; but as has been pointed out before, this is likely an issue with libedit.