@@ -827,8 +827,22 @@ private function restore_wp( $backup_dir ) {
827827 $ meta_data = json_decode ( file_get_contents ( $ backup_dir . '/meta.json ' ), true );
828828 $ wp_version = $ meta_data ['wordpressVersion ' ];
829829
830+ // $wp_version is read from the backup's meta.json and interpolated into the
831+ // shell command below (which runs through `bash -c` in the container), so a
832+ // crafted value could otherwise inject shell tokens. A WordPress version
833+ // only ever contains [0-9A-Za-z.-]; strip anything else so no shell
834+ // metacharacter can survive either shell layer.
835+ $ wp_version = preg_replace ( '/[^0-9A-Za-z.\-]/ ' , '' , (string ) $ wp_version );
836+
837+ // wp core download extracts the WordPress archive in PHP, which needs more
838+ // than a typical site's 128M memory_limit and OOMs on low-RAM hosts. Run it
839+ // under a higher limit via `php -d memory_limit=256M $(which wp)`, matching
840+ // the site-creation path in site-type-wp. The command runs through `bash -c`
841+ // in the container, so the `$` in `$(which wp)` is escaped here to defer the
842+ // substitution to the container's shell (EE's `wp` is the phar, invoked
843+ // directly, so the WP_CLI_PHP_ARGS env var would not apply).
830844 $ args = [ 'shell ' , $ this ->site_data ['site_url ' ] ];
831- $ assoc_args = [ 'command ' => sprintf ( ' wp core download --force --version=%s' , $ wp_version ) ];
845+ $ assoc_args = [ 'command ' => sprintf ( " php -d memory_limit=256M \\ $(which wp) core download --force --version=%s" , $ wp_version ) ];
832846 $ options = [ 'skip-tty ' => true ];
833847 EE ::run_command ( $ args , $ assoc_args , $ options );
834848
0 commit comments