From 076e09b195160db3d8dc4602bd5b1efbfb5d9868 Mon Sep 17 00:00:00 2001 From: Yip Rui Fung Date: Thu, 4 Feb 2021 19:59:45 +0800 Subject: [PATCH] Prevent user from being able to override the collate / charset table creation options. Bad things would probably happen if they changed it to something that isn't some kind of unicode encoding. Signed-off-by: Yip Rui Fung --- config/config.sample.php | 11 +++++------ lib/private/DB/ConnectionFactory.php | 29 +++++++++++++++++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/config/config.sample.php b/config/config.sample.php index 7aaa98f831..a4c12a1376 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -1513,18 +1513,17 @@ $CONFIG = [ 'mysql.utf8mb4' => false, /** - * This configuration parameter can be used to override the default options used for table creation. - * This parameter will take precedence over mysql.utf8mb4 if that is set to true. + * This configuration parameter can be used to add or change the default options used for table creation. + * For changing charset / collation see mysql.utf8mb4 * * An example use for this parameter is where MariaDB page compression is enabled by default as the * COMPRESSED row format is not allowed there, and thus table creation will fail. - * This option can then be used to override this and change/remove the row_format option. + * This option can then be used to override this and change the row_format option. * */ 'dbdefaulttableoptions' => [ - 'collate' => 'utf8mb4_bin', - 'charset' => 'utf8mb4', - 'row_format' => 'compressed' + 'row_format' => 'dynamic', + 'page_compressed' => '1' ], /** diff --git a/lib/private/DB/ConnectionFactory.php b/lib/private/DB/ConnectionFactory.php index 4ba606f5dd..9ed8b87747 100644 --- a/lib/private/DB/ConnectionFactory.php +++ b/lib/private/DB/ConnectionFactory.php @@ -216,19 +216,34 @@ class ConnectionFactory { } // set default table creation options - $connectionParams['defaultTableOptions'] = $this->config->getValue('dbdefaulttableoptions', [ - 'collate' => 'utf8_bin' - ]); + $defaultTableOptions = [ + 'collate' => 'utf8_bin', + 'tablePrefix' => $connectionParams['tablePrefix'] + ]; - if ($this->config->getValue('mysql.utf8mb4', false) && is_null($this->config->getValue('dbdefaulttableoptions'))) { - $connectionParams['defaultTableOptions'] = [ + if ($this->config->getValue('mysql.utf8mb4', false)) { + $defaultTableOptions = [ 'collate' => 'utf8mb4_bin', 'charset' => 'utf8mb4', - 'row_format' => 'compressed' + 'row_format' => 'compressed', + 'tablePrefix' => $connectionParams['tablePrefix'] ]; } - $connectionParams['defaultTableOptions']['tablePrefix'] = $connectionParams['tablePrefix']; + $configTableOptions = $this->config->getValue('dbdefaulttableoptions', []); + + // prevent user from overriding collation / charset and tablePrefix here (previous behavior.) + if (array_key_exists('collate', $configTableOptions)) { + unset($configTableOptions['collate']); + } + if (array_key_exists('charset', $configTableOptions)) { + unset($configTableOptions['charset']); + } + if (array_key_exists('tablePrefix', $configTableOptions)) { + unset($configTableOptions['tablePrefix']); + } + + $connectionParams['defaultTableOptions'] = array_merge($defaultTableOptions, $configTableOptions); return $connectionParams; }