From 4c7f91822b985ff43bae8922a2c4ab9763db1055 Mon Sep 17 00:00:00 2001 From: Romain Menke <11521496+romainmenke@users.noreply.github.com> Date: Tue, 28 Nov 2023 00:04:04 +0100 Subject: [PATCH] fix: stackoverflow in `ReadFrom` (#925) * fix stackoverflow in ReadFrom - failing test * fix stackoverflow --- http/interceptor.go | 2 +- http/interceptor_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/http/interceptor.go b/http/interceptor.go index a7b616ab5..2f3352e97 100644 --- a/http/interceptor.go +++ b/http/interceptor.go @@ -109,7 +109,7 @@ func (i *rwInterceptor) Header() http.Header { } func (i *rwInterceptor) ReadFrom(r io.Reader) (n int64, err error) { - return io.Copy(i, r) + return io.Copy(struct{ io.Writer }{i}, r) } func (i *rwInterceptor) Flush() { diff --git a/http/interceptor_test.go b/http/interceptor_test.go index e4da8e700..d232996bf 100644 --- a/http/interceptor_test.go +++ b/http/interceptor_test.go @@ -214,6 +214,11 @@ func TestReadFrom(t *testing.T) { t.Errorf("unexpected error: %v", err) } + _, err = rw.(io.ReaderFrom).ReadFrom(struct{ io.Reader }{bytes.NewBuffer([]byte("hello world"))}) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + err = responseProcessor(tx, req) if err != nil { t.Errorf("unexpected error: %v", err)