valyala/fasthttp · error
too much data inflated: %d
Error message
too much data inflated: %d
What it means
WriteInflate is the raw-flate counterpart of WriteGunzip: bounded copy + int overflow guard. When inflated output exceeds maxBodySize, the 'too much data inflated' error is returned instead of an integer overflow.
Source
Thrown at compress.go:341
}
// WriteInflate writes inflated p to w and returns the number of uncompressed
// bytes written to w.
func WriteInflate(w io.Writer, p []byte) (int, error) {
return writeInflate(w, p, 0)
}
func writeInflate(w io.Writer, p []byte, maxBodySize int) (int, error) {
r := &byteSliceReader{b: p}
zr, err := acquireFlateReader(r)
if err != nil {
return 0, err
}
n, err := copyZeroAllocWithLimit(w, zr, maxBodySize)
releaseFlateReader(zr)
nn := int(n)
if int64(nn) != n {
return 0, fmt.Errorf("too much data inflated: %d", n)
}
return nn, err
}
// AppendInflateBytes appends inflated src to dst and returns the resulting dst.
func AppendInflateBytes(dst, src []byte) ([]byte, error) {
w := &byteSliceWriter{b: dst}
_, err := WriteInflate(w, src)
return w.b, err
}
type byteSliceWriter struct {
b []byte
}
func (w *byteSliceWriter) Write(p []byte) (int, error) {
w.b = append(w.b, p...)
return len(p), nilView on GitHub (pinned to c96f600972)
Solutions
- Stream with flate.NewReader plus an io.LimitReader bound
- Cap compressed input size before inflating
- Verify the expected decompressed size from protocol headers first
- Switch to gzip/zlib framing which often carries length metadata (ISIZE) for pre-checks
Example fix
// before err := fasthttp.WriteInflate(buf, deflatedBody) // after fr := flate.NewReader(bytes.NewReader(deflatedBody)) _, err := io.Copy(io.Discard, io.LimitReader(fr, maxDecompressed)) // bounded streaming
Defensive patterns
Strategy: validation
Validate before calling
if len(deflated) > maxCompressedInput { return errors.New("compressed payload too large") } Try / catch
if err := fasthttp.WriteInflate(buf, body); err != nil {
if strings.Contains(err.Error(), "too much data inflated") {
// switch to bounded streaming inflate
}
} Prevention
- Cap input size before inflating
- Stream with flate.NewReader + io.LimitReader
- For untrusted payloads prefer gzip/zlib framing with size headers
When it happens
Trigger: Calling fasthttp.WriteInflate (or AppendInflateBytes/inflateData) with raw DEFLATE data whose decompressed size exceeds maxBodySize.
Common situations: Handling HTTP deflate-encoded responses of unusual size, decompressing zlib/deflate blobs from untrusted sources, legacy protocol payloads without size caps.
Related errors
- too much data gunzipped: %d
- must implement readat
- directory index required
- no 'create file' permissions
- seek is not implemented
AI-assisted analysis of valyala/fasthttp@c96f600972 (2026-08-31).
Data as JSON: /api/errors/629cae6a1460dac1.
Report an issue: GitHub.