From: Matt Joiner Date: Thu, 14 Aug 2025 02:15:23 +0000 (+1000) Subject: Fix out of bounds in mmap WriteTo X-Git-Tag: v1.59.0~2^2~13 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c2ad0fc11fb5e4aed540c487324c7b37cc2237b7;p=btrtrc.git Fix out of bounds in mmap WriteTo --- diff --git a/storage/file-io-mmap.go b/storage/file-io-mmap.go index ed181f3c..422c1c0a 100644 --- a/storage/file-io-mmap.go +++ b/storage/file-io-mmap.go @@ -186,7 +186,11 @@ type mmapFileHandle struct { } func (me *mmapFileHandle) WriteTo(w io.Writer) (n int64, err error) { - n1, err := w.Write(me.shared.f.m[me.pos:]) + b := me.shared.f.m + if me.pos >= int64(len(b)) { + return + } + n1, err := w.Write(b[me.pos:]) n = int64(n1) me.pos += n return