egametang/ET · error · Exception
bufferList length < coutn, buffer length: {buffer.Length} {o
Error message
bufferList length < coutn, buffer length: {buffer.Length} {offset} {count} What it means
CircularBuffer.Read(byte[], int offset, int count) throws when the destination array is too small to hold offset+count bytes. This is a caller contract check: the output buffer must be large enough for the region you requested.
Source
Thrown at Packages/cn.etetet.core/Scripts/Core/Share/Network/Circularbuffer.cs:206
// }
//
// this.LastIndex += n;
//
// if (this.LastIndex == this.ChunkSize)
// {
// this.AddLast();
// this.LastIndex = 0;
// }
//
// return n;
//}
// 把CircularBuffer中数据写入buffer
public override int Read(byte[] buffer, int offset, int count)
{
if (buffer.Length < offset + count)
{
throw new Exception($"bufferList length < coutn, buffer length: {buffer.Length} {offset} {count}");
}
long length = this.Length;
if (length < count)
{
count = (int)length;
}
int alreadyCopyCount = 0;
while (alreadyCopyCount < count)
{
int n = count - alreadyCopyCount;
if (ChunkSize - this.FirstIndex > n)
{
Array.Copy(this.First, this.FirstIndex, buffer, alreadyCopyCount + offset, n);
this.FirstIndex += n;
alreadyCopyCount += n;
}View on GitHub (pinned to 5cab01f7a8)
Solutions
- Ensure buffer.Length >= offset + count (size the cache to the largest possible read).
- Prefer the stream overload when the destination size is uncertain.
- Reset offset to 0 between reads on a reused cache.
Example fix
// before buffer.Read(this.cache, 0, InnerPacketSizeLength); // cache too small // after this.cache = new byte[Math.Max(8, InnerPacketSizeLength)]; buffer.Read(this.cache, 0, InnerPacketSizeLength);
Defensive patterns
Strategy: validation
Validate before calling
if (buffer == null || buffer.Length < offset + count)
throw new ArgumentException("destination buffer too small");
bufffer.Read(buffer, offset, count); Type guard
static bool FitsBuffer(byte[] b, int offset, int count) => b != null && offset >= 0 && count >= 0 && b.Length >= offset + count;
Try / catch
null
Prevention
- Size reusable cache buffers to the max read constant.
- Keep offset at 0 for sequential reads on a shared cache.
- Assert buffer invariants at the call site.
When it happens
Trigger: Passing a small cache buffer with a count larger than its usable length, e.g. reading InnerPacketSizeLength (4) into a 2-byte array, or a non-zero offset that pushes count past the array end.
Common situations: Reused cache buffer that was shrunk, wrong constant for the read size, or off-by-one in offset math.
Related errors
- bufferList length < count, {Length} {count}
- ArgumentOutOfRange_Index
- Arg_ArrayPlusOffTooSmall
- Argument_IncompatibleArrayType
- string mode < 0: {strText} {mode}
AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13).
Data as JSON: /api/errors/bdbafc253ac4875f.
Report an issue: GitHub.