Skip to content

zstd decoder: memory accumulation and potential data loss in history.ensureBlock() #1112

@iblancasa

Description

@iblancasa

When the buffer needs to grow (capacity < target), the current implementation discards existing data:

  if cap(h.b) < h.allocFrameBuffer {
      h.b = make([]byte, 0, h.allocFrameBuffer)  // ❌ Existing data lost!
      return
  }

Any data in h.b is lost when the buffer is reallocated.

Also, the buffers never shrink. Once a decoder allocates a large buffer (e.g., 8MB for a large frame), it retains that memory permanently, even when subsequent frames are much smaller (e.g., 1MB).

Long-running services that process varying frame sizes will accumulate and hold onto peak memory usage indefinitely.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions