JuliusBrussee/caveman · error
invalid decompression limit
Error message
invalid decompression limit %d
What it means
DecompressLimit was called with a maxBytes ceiling that is negative or larger than DefaultMaxDecompressedBytes. The library enforces a global upper bound on decompressed output to prevent decompression-bomb memory exhaustion, so out-of-range limits are rejected up front with this error before any decoding begins. The %d shows the offending value.
Solutions
- Clamp the limit into the valid range: 0 <= maxBytes <= DefaultMaxDecompressedBytes.
- Do not attempt to disable the ceiling; instead decompress in chunks or use a streaming decoder if you need more than the default.
- Validate config-derived limits at startup, failing fast on out-of-range values.
- Check for arithmetic bugs (unit conversion, int overflow) producing the bad value.
- Use Decompress (which applies the default ceiling) when you have no specific size requirement.
Example fix
// before
out, err := objectstore.DecompressLimit(codec, data, -1) // invalid decompression limit -1
// after
limit := int64(cfg.MaxDecompressedMB) << 20
if limit <= 0 || limit > objectstore.DefaultMaxDecompressedBytes {
limit = objectstore.DefaultMaxDecompressedBytes
}
out, err := objectstore.DecompressLimit(codec, data, limit) Defensive patterns
Strategy: validation
Validate before calling
if maxBytes < 0 || maxBytes > objectstore.DefaultMaxDecompressedBytes {
maxBytes = objectstore.DefaultMaxDecompressedBytes
}
out, err := objectstore.DecompressLimit(codec, data, maxBytes) Try / catch
if err != nil {
if strings.HasPrefix(err.Error(), "invalid decompression limit") {
// clamp and retry once rather than failing the operation
out, err = objectstore.DecompressLimit(codec, data, objectstore.DefaultMaxDecompressedBytes)
}
if err != nil {
return err
}
} Prevention
- Never use -1 or math.MaxInt64 to mean 'unlimited'; use Decompress for the default ceiling.
- Validate size limits at startup with explicit unit conversions (MB -> bytes).
- Centralize limit derivation in one helper so bounds are checked once.
- Add unit tests for boundary values (0, DefaultMaxDecompressedBytes, -1).
When it happens
Trigger: Calling DecompressLimit with maxBytes < 0, or maxBytes > DefaultMaxDecompressedBytes — e.g. passing -1 as 'unlimited', reading a limit from config as raw int64 without bounds, or arithmetic overflow producing a huge value.
Common situations: Developers attempting to disable the limit by passing math.MaxInt64 or -1, config values in bytes misinterpreted (GB value fed as byte count), or a caller converting a user-supplied 'max size in MB' incorrectly.
Related errors
- unknown compression codec
- arm must be or
- cave_budget_release_exceeds_max
- CAVEMAN_CCR_MAX_BYTES must be a positive integer
- ccr max storage bytes must be positive
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/dbc2fd7e5aa22f3d.
Report an issue: GitHub.
Appendix: source
Thrown at shared/platform/objectstore/compress.go:68
return zstdEnc.EncodeAll(data, nil), nil
default:
return nil, fmt.Errorf("unknown compression codec %q", codec)
}
}
// Decompress reverses Compress with a defensive default expansion ceiling. An
// unknown codec fails closed.
func Decompress(codec string, data []byte) ([]byte, error) {
return DecompressLimit(codec, data, DefaultMaxDecompressedBytes)
}
// DecompressLimit reverses Compress while refusing to produce more than
// maxBytes of plaintext. The limit is applied while decoding gzip and through
// zstd's decoder memory bound, so highly-compressible hostile payloads cannot
// first allocate their full expanded size and only then be rejected.
func DecompressLimit(codec string, data []byte, maxBytes int64) ([]byte, error) {
if maxBytes < 0 || maxBytes > DefaultMaxDecompressedBytes {
return nil, fmt.Errorf("invalid decompression limit %d", maxBytes)
}
switch codec {
case CompressionNone, "":
if int64(len(data)) > maxBytes {
return nil, ErrDecompressedTooLarge
}
return data, nil
case CompressionGzip:
zr, err := gzip.NewReader(bytes.NewReader(data))
if err != nil {
return nil, fmt.Errorf("gzip reader: %w", err)
}
defer zr.Close()
out, err := io.ReadAll(io.LimitReader(zr, maxBytes+1))
if err != nil {
return nil, fmt.Errorf("gzip read: %w", err)
}
if int64(len(out)) > maxBytes {View on GitHub (pinned to 3ee70a1026)