diff options
author | hmhealey <harrisonmhealey@gmail.com> | 2015-10-26 14:38:46 -0400 |
---|---|---|
committer | hmhealey <harrisonmhealey@gmail.com> | 2015-10-26 14:53:56 -0400 |
commit | 9635bfdd4f3925b0f6f0873508216824b604ac10 (patch) | |
tree | f0b176d4f4e89b0d3159dafd4f22173b547b0e50 /api/user.go | |
parent | ff6e91f51d844a4703d3c4648b8b6bffe0cdabbc (diff) | |
download | chat-9635bfdd4f3925b0f6f0873508216824b604ac10.tar.gz chat-9635bfdd4f3925b0f6f0873508216824b604ac10.tar.bz2 chat-9635bfdd4f3925b0f6f0873508216824b604ac10.zip |
Prevented image files larger than 4k resolution from being uploaded
Diffstat (limited to 'api/user.go')
-rw-r--r-- | api/user.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/api/user.go b/api/user.go index 06e5336f1..3796a50ee 100644 --- a/api/user.go +++ b/api/user.go @@ -855,6 +855,18 @@ func uploadProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { return } + // Decode image config first to check dimensions before loading the whole thing into memory later on + config, _, err := image.DecodeConfig(file) + if err != nil { + c.Err = model.NewAppError("uploadProfileFile", "Could not decode profile image config.", err.Error()) + return + } else if config.Width*config.Height > MaxImageSize { + c.Err = model.NewAppError("uploadProfileFile", "Unable to upload profile image. File is too large.", err.Error()) + return + } + + file.Seek(0, 0) + // Decode image into Image object img, _, err := image.Decode(file) if err != nil { |