Make sure that lua stack trace is valid UTF-8.

This fixes a warning on php8.1 related to preg_match_all returning
null when given invalid UTF-8.

I made a separate patch to change the null into an exception Ic0c9083b

In a sense, this is a follow-up to ec103b6966.

Bug: T319218
Change-Id: Ia17fc2fa428ec35bdbd242f1127fcdff501fb741
This commit is contained in:
Brian Wolff 2022-10-04 10:39:21 -07:00 committed by Legoktm
parent 0f2585244c
commit 047200c11e
2 changed files with 18 additions and 1 deletions

View file

@ -81,7 +81,16 @@ class LuaSandboxInterpreter extends LuaInterpreter {
protected function convertSandboxError( LuaSandboxError $e ) {
$opts = [];
if ( isset( $e->luaTrace ) ) {
$opts['trace'] = $e->luaTrace;
$trace = $e->luaTrace;
foreach ( $trace as &$val ) {
$val = array_map( static function ( $val ) {
if ( is_string( $val ) ) {
$val = Validator::cleanUp( $val );
}
return $val;
}, $val );
}
$opts['trace'] = $trace;
}
$message = Validator::cleanUp( $e->getMessage() );
if ( preg_match( '/^(.*?):(\d+): (.*)$/', $message, $m ) ) {

View file

@ -416,6 +416,14 @@ class LuaStandaloneInterpreter extends LuaInterpreter {
$message['value'] = $m[3];
}
if ( isset( $message['trace'] ) ) {
foreach ( $message['trace'] as &$val ) {
$val = array_map( static function ( $val ) {
if ( is_string( $val ) ) {
$val = Validator::cleanUp( $val );
}
return $val;
}, $val );
}
$opts['trace'] = array_values( $message['trace'] );
}
throw $this->engine->newLuaError( $message['value'], $opts );