From f1420cf48418c01694eaf3110ac411915b217d36 Mon Sep 17 00:00:00 2001 From: Ting-Yu Wang Date: Fri, 15 Jan 2021 12:48:58 -0800 Subject: Add sanity check on return values from Write io.Writer.Write requires err to be non-nil if n < len(v). We could allow this but it will be irreversible if users depend on this behavior. Ported the test that discovered this. PiperOrigin-RevId: 352065946 --- pkg/tcpip/buffer/view.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pkg/tcpip') diff --git a/pkg/tcpip/buffer/view.go b/pkg/tcpip/buffer/view.go index 5dd1b1b6b..09d3dac66 100644 --- a/pkg/tcpip/buffer/view.go +++ b/pkg/tcpip/buffer/view.go @@ -17,6 +17,7 @@ package buffer import ( "bytes" + "fmt" "io" ) @@ -167,6 +168,9 @@ func (vv *VectorisedView) ReadTo(dst io.Writer, count int, peek bool) (int, erro if err != nil { break } + if n != len(v) { + panic(fmt.Sprintf("io.Writer.Write succeeded with incomplete write: %d != %d", n, len(v))) + } } if !peek { vv.TrimFront(done) -- cgit v1.2.3