Skip to content

writer-buffer-mutation

Detect io.Writer implementations that modify their input buffer.

Updated View as Markdown

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

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

Good

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

Type to search…

↑↓ navigate↵ selectEsc close