Page 1 of 1

Bug: Crash running on MSSQL when upload dir > 2GB

Posted: Wed May 09, 2018 8:25 pm
by gsmaclean
I'm posting this in case anyone else comes across the same issue, until it gets fixed in the mainline code. This problem is encountered when running PHPBB against MSSQL, any version.

My upload (files) directory exceeded 2GB recently, and when this occurred, anyone attempting to post an image with an attachment received this error:

Code: Select all

SQL ERROR [ mssqlnative ]

SQLSTATE: 22003 code: 8115 message: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type int. SQLSTATE: 01000 code: 3621 message: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]The statement has been terminated. [3621]


UPDATE phpbb_config SET config_value = config_value + 157133 WHERE config_name = 'upload_dir_size'
(157133 was the size of the file in bytes that I was trying to attach)

The problem is that the config value is supposed to be converted to a bigint before being written to the database, but there was never a "conversion to bigint" implementation written in the MSSQL driver. So MSSQL defaults to using int, and the largest number you can store in an int is 2,147,483,647. Once your upload directory exceeds this value (in bytes), this crash will occur when attempting to upload any more attachments.

To fix the bug, open \phpbb\db\driver\mssql_base.php. Add the following missing function override to it:

Code: Select all

* {@inheritDoc}
function cast_expr_to_bigint($expression)
	return 'CONVERT(BIGINT, ' . $expression . ')';
I have also reported this issue in the bug tracker: