From d9fa9bddda3783a2c6784b5d2d416580f106b57a Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Mon, 23 May 2022 02:40:16 -0700 Subject: [PATCH] Prevent panic for zero-length input --- pcre.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pcre.go b/pcre.go index 1036598..024c719 100644 --- a/pcre.go +++ b/pcre.go @@ -574,6 +574,10 @@ func replaceBytes(src, repl []byte, sOff, eOff lib.Tsize_t, diff int64) (int64, // match calls the underlying pcre match functions. It re-runs the functions // until no matches are found if multi is set to true. func (r *Regexp) match(b []byte, options uint32, multi bool) ([][]lib.Tsize_t, error) { + if len(b) == 0 { + return nil, nil + } + r.mtx.Lock() defer r.mtx.Unlock()