Skip to content

Fix false "invalid file size" error on boards with unlimited attachment size - #17

Open
ECYaz wants to merge 1 commit into
danieltj27:latestfrom
ECYaz:fix/badge-upload-invalid-filesize
Open

Fix false "invalid file size" error on boards with unlimited attachment size#17
ECYaz wants to merge 1 commit into
danieltj27:latestfrom
ECYaz:fix/badge-upload-invalid-filesize

Conversation

@ECYaz

@ECYaz ECYaz commented Jul 18, 2026

Copy link
Copy Markdown

Problem

Uploading a custom verification badge fails with "The image you uploaded has an invalid file size." on some boards, for every file and file type.

In acp/settings_module.php, the size check compares the upload against $config['max_filesize'] directly:

$max_size = $config[ 'max_filesize' ];

if ( '0' !== $file_upload[ 'error' ] || 1 > $file_upload[ 'size' ] || $max_size < $file_upload[ 'size' ] ) {

In phpBB, an attachment max_filesize of 0 means "no limit" (that's how the core attachment settings treat it). On any board configured that way, $max_size < $file_upload['size'] is 0 < <size>, which is always true, so the size check rejects every upload before the file-type check is even reached. Boards left on the default limit (262144) with a small badge are unaffected — which is why it only happens on some installs, and why it looks like it applies to all file types.

Fix

Cast the setting to int and only enforce the maximum when it is greater than zero:

$max_size = (int) $config[ 'max_filesize' ];

if ( '0' !== $file_upload[ 'error' ] || 1 > $file_upload[ 'size' ] || ( 0 < $max_size && $max_size < $file_upload[ 'size' ] ) ) {

Behaviour before/after (size gate only):

Case Before After
default limit, small badge allow allow
unlimited (max_filesize = 0), small badge reject allow
admin limit set, badge under limit allow allow
admin limit set, badge over limit reject reject

The change only affects the max_filesize == 0 case; a genuinely oversized upload against a set limit is still rejected.

Scoped to this one issue — no other changes.

The custom badge upload compared the file size against $config['max_filesize']
directly. In phpBB a max_filesize of 0 means "no limit", so on boards configured
that way the check `$max_size < $file_upload['size']` was always true and every
upload was rejected with "The image you uploaded has an invalid file size."
(regardless of file type). Cast the setting to int and only enforce it when it
is greater than 0.
@danieltj27 danieltj27 self-assigned this Jul 18, 2026
@danieltj27 danieltj27 added the Bug 🐞 An error that needs fixing. label Jul 18, 2026
@danieltj27 danieltj27 added this to the Future Release milestone Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug 🐞 An error that needs fixing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants