From 9b4da88a96ce4c793e7b15d9b340fa6326a29a82 Mon Sep 17 00:00:00 2001 From: uki00a Date: Wed, 20 May 2020 23:34:20 +0900 Subject: fix(std/io): BufReader should not share the internal buffer across reads (#4543) --- std/io/bufio.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'std/io/bufio.ts') diff --git a/std/io/bufio.ts b/std/io/bufio.ts index aa74809fe..5c005672a 100644 --- a/std/io/bufio.ts +++ b/std/io/bufio.ts @@ -338,7 +338,11 @@ export class BufReader implements Reader { // Buffer full? if (this.buffered() >= this.buf.byteLength) { this.r = this.w; - throw new BufferFullError(this.buf); + // #4521 The internal buffer should not be reused across reads because it causes corruption of data. + const oldbuf = this.buf; + const newbuf = this.buf.slice(0); + this.buf = newbuf; + throw new BufferFullError(oldbuf); } s = this.w - this.r; // do not rescan area we scanned before -- cgit v1.2.3