diff --git a/stream/stream.c b/stream/stream.c index c318554feb..1f50c70344 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -402,7 +402,8 @@ struct bstr stream_peek(stream_t *s, int len) // Fill rest of the buffer. while (buf_valid < len) { int chunk = MPMAX(len - buf_valid, STREAM_BUFFER_SIZE); - assert(buf_valid + chunk <= TOTAL_BUFFER_SIZE); + if (buf_valid + chunk > TOTAL_BUFFER_SIZE) + chunk = TOTAL_BUFFER_SIZE - buf_valid; int read = stream_read_unbuffered(s, &s->buffer[buf_valid], chunk); if (read == 0) break; // EOF