element-hq / element-hq/synapse

Please set a separate error message for "uploading an avatar."

Open
#18,861 1 comment 0 reactions 0 assignees View on GitHub
A-Media-Repository A-Profiles
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

### Description

Synapse currently handles "uploading an image file that exceeds the specified size" with the same error message as for "normal file uploads," rather than a separate error code or error message. This is misleading to clients and users.

For example:
Synapse is configured with a maximum file upload size of 100 MB and a maximum avatar upload size of 5 MB. If I try to upload a 6 MB image as an avatar, the client (Element Web) will tell me that the uploaded image exceeds 100 MB.

Related:
https://github.com/element-hq/element-web/issues/29462

### Steps to reproduce

Uploading an image between the two limits as an avatar in Elemnet Web (profile UI).

### Homeserver

Self-hosted

### Synapse Version

Synapse 1.136.0

### Installation Method

Docker (matrixdotorg/synapse)

### Database

Postgres 16.x (singlePG instance, no, no)

### Workers

Single process

### Platform

Synology DIskStation Manager 6.2.3 (Linux 3.10.105)

### Configuration

```
max_avatar_size: 5M
max_upload_size: 512M
```

### Relevant log output

```shell
synapse.rest.media.upload_resource - 131 - INFO - POST-821824 - Uploaded content with URI 'mxc://example.com/VqIPrwBmttDtbUhaRZcwQCKT'
synapse.access.http.8008 - 515 - INFO - POST-821824 - **************** - 8008 - {@test8:example.com} Processed request: 3.496sec/0.000sec (3.247sec, 0.214sec) (0.002sec/0.028sec/8) 71B 200 "POST /_matrix/media/v3/upload?filename=avatar.png HTTP/1.0" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Element/1.11.109 Chrome/138.0.7204.100 Electron/37.2.3 Safari/537.36" [0 dbevts]
synapse.handlers.profile - 395 - WARNING - PUT-821837 - Forbidding avatar change to mxc://example.com/VqIPrwBmttDtbUhaRZcwQCKT: 13446959 bytes is above the allowed size limit
```
The log shows that although the file itself was uploaded successfully, an error occurred when setting it as the avatar.
This doesn't reflect what I'm trying to say.

### Anything else that would be useful to know?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in synapse.handlers.profile, where the avatar size limit is rejected, and compare that flow with synapse.rest.media.upload_resource and the reported max_avatar_size/max_upload_size settings. Trace the response returned when an avatar exceeds its limit and verify that clients can distinguish it from a normal upload-size failure; done means the avatar-specific error is exposed without changing successful uploads.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.