gohugoio/hugo · error

received invalid image dimensions: %dx%d stride %d

Error message

received invalid image dimensions: %dx%d stride %d

What it means

Raised in Hugo's WASM-based AVIF decoder (internal/warpc/avif.go:131) after the sandboxed libavif module returns decode results. The returned header params (width, height, stride) are sanity-checked; a zero in any of them means the decoded pixel geometry is unusable, so Hugo fails fast rather than constructing an invalid image.

Source

Thrown at internal/warpc/avif.go:132

			RequestKinds:  []string{MessageKindJSON, MessageKindBlob},
			ResponseKinds: []string{MessageKindJSON, MessageKindBlob},
		},

		Data: AvifInput{
			Source:      source,
			Destination: &destination,
			Options:     map[string]any{},
		},
	}

	out, err := dd.Execute(context.Background(), message)
	if err != nil {
		return nil, err
	}

	w, h, stride, depth := out.Data.Params.Width, out.Data.Params.Height, out.Data.Params.Stride, out.Data.Params.Depth
	if w == 0 || h == 0 || stride == 0 {
		return nil, fmt.Errorf("received invalid image dimensions: %dx%d stride %d", w, h, stride)
	}

	// For 10+ bit HDR images, the C code returns 16-bit RGBA data.
	isHDR := depth > 8

	// libavif returns 16-bit data in native (little-endian) byte order,
	// but Go's NRGBA64 expects big-endian. Swap bytes for HDR images.
	if isHDR {
		pix := destination.Bytes()
		for i := 0; i < len(pix); i += 2 {
			pix[i], pix[i+1] = pix[i+1], pix[i]
		}
	}

	if len(out.Data.Params.FrameDurations) > 0 {
		img := &AnimatedImage{
			frameDurations:          out.Data.Params.FrameDurations,
			loopCount:               avifLoopCountToGo(out.Data.Params.LoopCount),

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Verify the source file is a valid AVIF: run `avifdec` or `ffprobe` on it, or open it in a browser.
  2. Re-export/re-encode the image from the original source (e.g. `avifenc input.png out.avif`).
  3. Check the file isn't a git-lfs pointer or truncated asset (compare file size to the original).
  4. If all AVIFs fail after an upgrade, reinstall the official Hugo extended binary.
Defensive patterns

Strategy: validation

Validate before calling

cfg, _, err := image.DecodeConfig(reader)
if err != nil || cfg.Width <= 0 || cfg.Height <= 0 || cfg.Width*cfg.Height > maxPixels {
    return fmt.Errorf("reject image %dx%d", cfg.Width, cfg.Height)
}

Try / catch

img, err := decodeAVIF(buf)
if err != nil {
    // corrupt/hostile file — skip asset, log source path, do not retry
    return fmt.Errorf("avif decode %s: %w", path, err)
}

Prevention

When it happens

Trigger: Processing an .avif image through Hugo's image pipeline (resources.Get + .Resize/.Process, or any decode path hitting AvifCodec.Decode) where the WASM libavif module reports width, height, or stride of 0 in its JSON response.

Common situations: Corrupted or truncated AVIF files (bad download, git-lfs pointer file with .avif extension); files that are not actually AVIF; malformed AVIF produced by buggy encoders; rarely, a mismatch between the Hugo binary and its embedded WASM module after a broken build.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/c9132c201bb1fa23.json. Report an issue: GitHub ↗.