Fixing slice runtime error due to unset byte slice capacity
@@ -8,6 +8,7 @@ import (
"crypto/sha1"
"io/ioutil"
"os"
+ "reflect"
"unsafe"
"github.com/projectdiscovery/nuclei/v2/pkg/output"
@@ -106,5 +107,7 @@ func (s *Storage) Index(result *output.ResultEvent) (bool, error) {
//
// Reference - https://stackoverflow.com/questions/59209493/how-to-use-unsafe-get-a-byte-slice-from-a-string-without-memory-copy
func unsafeToBytes(data string) []byte {
- return *(*[]byte)(unsafe.Pointer(&data))
+ var buf = *(*[]byte)(unsafe.Pointer(&data))
+ (*reflect.SliceHeader)(unsafe.Pointer(&buf)).Cap = len(data)
+ return buf
}
