[MM-69126] Fix custom emoji upload size and GIF frame limits (#36984) (#37088)

* [MM-69126] Fix custom emoji upload size and GIF frame limits

* Assert 413 status and error ID in oversized emoji test

* Raise max emoji GIF frames to 70

* Enforce emoji GIF frame limit on the direct-write path
Этот коммит содержится в:
Felipe Martin
2026-06-25 12:05:34 +02:00
коммит произвёл GitHub
родитель cbfcecb37c
Коммит 638007314e
4 изменённых файлов: 66 добавлений и 4 удалений

Просмотреть файл

@@ -48,12 +48,18 @@ func createEmoji(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
r.Body = http.MaxBytesReader(w, r.Body, app.MaxEmojiFileSize)
if err := r.ParseMultipartForm(app.MaxEmojiFileSize); err != nil {
c.Err = model.NewAppError("createEmoji", "api.emoji.create.parse.app_error", nil, "", http.StatusBadRequest).Wrap(err)
return
}
auditRec := c.MakeAuditRecord("createEmoji", model.AuditStatusFail)
if imageFiles := r.MultipartForm.File["image"]; len(imageFiles) > 0 && imageFiles[0].Size > app.MaxEmojiFileSize {
c.Err = model.NewAppError("createEmoji", "api.emoji.create.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)
return
}
auditRec := c.MakeAuditRecord(model.AuditEventCreateEmoji, model.AuditStatusFail)
defer c.LogAuditRec(auditRec)
// Allow any user with CREATE_EMOJIS permission at Team level to create emojis at system level

Просмотреть файл

@@ -164,8 +164,41 @@ func TestCreateEmoji(t *testing.T) {
Name: model.NewId(),
}
_, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestAnimatedGif(t, 100, 100, 10000), "image.gif")
_, resp, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestAnimatedGif(t, 100, 100, 10000), "image.gif")
require.Error(t, err, "should fail - emoji is too big")
CheckRequestEntityTooLargeStatus(t, resp)
CheckErrorID(t, err, "api.emoji.create.too_large.app_error")
// try to create an animated gif with too many frames
emoji = &model.Emoji{
CreatorId: th.BasicUser.Id,
Name: model.NewId(),
}
_, resp, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestAnimatedGif(t, 200, 200, app.MaxEmojiGIFFrames+1), "image.gif")
require.Error(t, err, "should fail - gif has too many frames")
CheckBadRequestStatus(t, resp)
CheckErrorID(t, err, "api.emoji.upload.too_many_frames.app_error")
// try to create an animated gif with too many frames that does not need resizing
emoji = &model.Emoji{
CreatorId: th.BasicUser.Id,
Name: model.NewId(),
}
_, resp, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestAnimatedGif(t, app.MaxEmojiWidth, app.MaxEmojiHeight, app.MaxEmojiGIFFrames+1), "image.gif")
require.Error(t, err, "should fail - gif has too many frames")
CheckBadRequestStatus(t, resp)
CheckErrorID(t, err, "api.emoji.upload.too_many_frames.app_error")
// try to create an animated gif with exactly the maximum allowed frames
emoji = &model.Emoji{
CreatorId: th.BasicUser.Id,
Name: model.NewId(),
}
_, _, err = client.CreateEmoji(context.Background(), emoji, utils.CreateTestAnimatedGif(t, 200, 200, app.MaxEmojiGIFFrames), "image.gif")
require.NoError(t, err, "should succeed - gif has exactly the maximum allowed frames")
// try to create an emoji with data that isn't an image
emoji = &model.Emoji{