From 7dc36739cf48996615f9d4134ff4971a2af36ee1 Mon Sep 17 00:00:00 2001 From: Weilin Du Date: Sun, 11 Oct 2026 23:00:09 +0800 Subject: [PATCH] Fix non-ASCII completion append characters in readline_info() Store the first byte as unsigned char to keep completion_append_character within the valid range of the one-character string table. --- NEWS | 4 +++ ext/readline/readline.c | 2 +- ...line_info_completion_append_character.phpt | 27 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 ext/readline/tests/readline_info_completion_append_character.phpt diff --git a/NEWS b/NEWS index aaed43baa2c8..43eaf4dbad43 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,10 @@ PHP NEWS - Phpdbg: . Fix wrong command names. (ndossche, Weilin Du) +- Readline: + . Fixed a crash in readline_info() when completion_append_character + contains a non-ASCII byte. (Weilin Du) + - SOAP: . Fixed use of uninitialized func in do_request() on OOM bailout. (David Carlier) diff --git a/ext/readline/readline.c b/ext/readline/readline.c index 838c74da86ce..f9287af2eff6 100644 --- a/ext/readline/readline.c +++ b/ext/readline/readline.c @@ -248,7 +248,7 @@ PHP_FUNCTION(readline_info) if (!try_convert_to_string(value)) { RETURN_THROWS(); } - rl_completion_append_character = (int)Z_STRVAL_P(value)[0]; + rl_completion_append_character = (unsigned char)Z_STRVAL_P(value)[0]; } RETVAL_INTERNED_STR( oldval == 0 ? ZSTR_EMPTY_ALLOC() : ZSTR_CHAR(oldval)); diff --git a/ext/readline/tests/readline_info_completion_append_character.phpt b/ext/readline/tests/readline_info_completion_append_character.phpt new file mode 100644 index 000000000000..88a0cf003388 --- /dev/null +++ b/ext/readline/tests/readline_info_completion_append_character.phpt @@ -0,0 +1,27 @@ +--TEST-- +readline_info(): completion_append_character supports non-ASCII bytes +--EXTENSIONS-- +readline +--SKIPIF-- + +--FILE-- + +--EXPECT-- +old= current=7f info=7f +old=7f current=80 info=80 +old=80 current=ff info=ff +old=ff current= info=