---
title: "writer-buffer-mutation"
description: "Detect io.Writer implementations that modify their input buffer."
image: "https://strider.gempir.com/og.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://strider.gempir.com/llms.txt
> Use this file to discover all available pages before exploring further.

# writer-buffer-mutation

**Default severity:** `error`

The `io.Writer` contract requires `Write` implementations not to modify the
provided byte slice, even temporarily. Mutating an element or appending into
the input can corrupt caller-owned data.

## Bad

```go
func (w *writer) Write(p []byte) (int, error) { p[0] = 0; return len(p), nil }
```

## Good

```go
func (w *writer) Write(p []byte) (int, error) { return w.dst.Write(p) }
```

Source: https://strider.gempir.com/analyzers/writer-buffer-mutation/index.mdx
