From 14a6322b4fc88b8cd42ee455ab940081de3d7b1d Mon Sep 17 00:00:00 2001 From: rxu Date: Mon, 10 Mar 2025 21:24:15 +0700 Subject: [PATCH] [ticket/17475] Fix MSSQL arithmetic overflow error on counting attachments size PHPBB-17475 --- phpBB/includes/acp/acp_attachments.php | 2 +- phpBB/includes/acp/acp_forums.php | 2 +- phpBB/includes/acp/acp_main.php | 2 +- phpBB/includes/functions_convert.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phpBB/includes/acp/acp_attachments.php b/phpBB/includes/acp/acp_attachments.php index 6b7d9f7b44..5813f719be 100644 --- a/phpBB/includes/acp/acp_attachments.php +++ b/phpBB/includes/acp/acp_attachments.php @@ -1077,7 +1077,7 @@ class acp_attachments $attachments_per_page = (int) $config['topics_per_page']; // Get total number or orphans older than 3 hours - $sql = 'SELECT COUNT(attach_id) as num_files, SUM(filesize) as total_size + $sql = 'SELECT COUNT(attach_id) as num_files, SUM(' . $this->db->cast_expr_to_bigint('filesize') . ') as total_size FROM ' . ATTACHMENTS_TABLE . ' WHERE is_orphan = 1 AND filetime < ' . (time() - 3*60*60); diff --git a/phpBB/includes/acp/acp_forums.php b/phpBB/includes/acp/acp_forums.php index ba3901f67a..57677544fa 100644 --- a/phpBB/includes/acp/acp_forums.php +++ b/phpBB/includes/acp/acp_forums.php @@ -2071,7 +2071,7 @@ class acp_forums $config->set('num_files', (int) $row['stat'], false); - $sql = 'SELECT SUM(filesize) as stat + $sql = 'SELECT SUM(' . $db->cast_expr_to_bigint('filesize') . ') as stat FROM ' . ATTACHMENTS_TABLE; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); diff --git a/phpBB/includes/acp/acp_main.php b/phpBB/includes/acp/acp_main.php index 2d4cb10c73..9ed450ca36 100644 --- a/phpBB/includes/acp/acp_main.php +++ b/phpBB/includes/acp/acp_main.php @@ -182,7 +182,7 @@ class acp_main $config->set('num_files', (int) $db->sql_fetchfield('stat'), false); $db->sql_freeresult($result); - $sql = 'SELECT SUM(filesize) as stat + $sql = 'SELECT SUM(' . $db->cast_expr_to_bigint('filesize') . ') as stat FROM ' . ATTACHMENTS_TABLE . ' WHERE is_orphan = 0'; $result = $db->sql_query($sql); diff --git a/phpBB/includes/functions_convert.php b/phpBB/includes/functions_convert.php index 1b499293d7..f980ab200d 100644 --- a/phpBB/includes/functions_convert.php +++ b/phpBB/includes/functions_convert.php @@ -1998,7 +1998,7 @@ function update_dynamic_config() $config->set('num_files', (int) $db->sql_fetchfield('stat'), false); $db->sql_freeresult($result); - $sql = 'SELECT SUM(filesize) as stat + $sql = 'SELECT SUM(' . $db->cast_expr_to_bigint('filesize') . ') as stat FROM ' . ATTACHMENTS_TABLE . ' WHERE is_orphan = 0'; $result = $db->sql_query($sql);