From ad377e3085d7e5c010c4ea6068fe9e4265cf57de Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Mon, 6 Nov 2023 21:16:22 +0000 Subject: [PATCH] MDL-79797 backup: ensure block config is safely unserialized. --- backup/moodle2/backup_stepslib.php | 8 +++++++- backup/moodle2/restore_stepslib.php | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/backup/moodle2/backup_stepslib.php b/backup/moodle2/backup_stepslib.php index 354e07d16c9..af3803bb952 100644 --- a/backup/moodle2/backup_stepslib.php +++ b/backup/moodle2/backup_stepslib.php @@ -1602,7 +1602,13 @@ class backup_block_instance_structure_step extends backup_structure_step { // Transform configdata information if needed (process links and friends) $blockrec = $DB->get_record('block_instances', array('id' => $this->task->get_blockid())); if ($attrstotransform = $this->task->get_configdata_encoded_attributes()) { - $configdata = (array)unserialize(base64_decode($blockrec->configdata)); + $configdata = array_filter( + (array) unserialize_object(base64_decode($blockrec->configdata)), + static function($value): bool { + return !($value instanceof __PHP_Incomplete_Class); + } + ); + foreach ($configdata as $attribute => $value) { if (in_array($attribute, $attrstotransform)) { $configdata[$attribute] = $this->contenttransformer->process($value); diff --git a/backup/moodle2/restore_stepslib.php b/backup/moodle2/restore_stepslib.php index 4155fcf4406..27cc4c873e0 100644 --- a/backup/moodle2/restore_stepslib.php +++ b/backup/moodle2/restore_stepslib.php @@ -4340,7 +4340,13 @@ class restore_block_instance_structure_step extends restore_structure_step { // Let's look for anything within configdata neededing processing // (nulls and uses of legacy file.php) if ($attrstotransform = $this->task->get_configdata_encoded_attributes()) { - $configdata = (array) unserialize_object(base64_decode($data->configdata)); + $configdata = array_filter( + (array) unserialize_object(base64_decode($data->configdata)), + static function($value): bool { + return !($value instanceof __PHP_Incomplete_Class); + } + ); + foreach ($configdata as $attribute => $value) { if (in_array($attribute, $attrstotransform)) { $configdata[$attribute] = $this->contentprocessor->process_cdata($value);