From e443049df9c2faa782b6bd13f7ba1137163d3ba2 Mon Sep 17 00:00:00 2001 From: pertsevpv Date: Wed, 5 Jun 2024 11:13:24 +0300 Subject: [PATCH] Add length limits 50 for silces and chans and 1000 for strings --- generator.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/generator.go b/generator.go index 42c4b18..89bd0ad 100644 --- a/generator.go +++ b/generator.go @@ -156,12 +156,14 @@ func (g *Generator) fillAny(any reflect.Value) error { any.SetUint(newUInt64) case reflect.Chan: - size, err := g.GenerateInt() + maxSize := uint8(50) + size, err := g.GenerateUInt8() if err != nil { return err } - channel := reflect.MakeChan(any.Type(), size) - for i := 0; i < size; i++ { + size = size % maxSize + channel := reflect.MakeChan(any.Type(), int(size)) + for i := 0; i < int(size); i++ { elem := reflect.New(channel.Type().Elem()).Elem() err = g.fillAny(elem) if err != nil { @@ -172,12 +174,15 @@ func (g *Generator) fillAny(any reflect.Value) error { any.Set(channel) case reflect.Slice: - size, err := g.GenerateInt() + maxSize := uint8(50) + size, err := g.GenerateUInt8() if err != nil { return err } - slice := reflect.MakeSlice(any.Type(), size, size) - for i := 0; i < size; i++ { + size = size % maxSize + + slice := reflect.MakeSlice(any.Type(), int(size), int(size)) + for i := 0; i < int(size); i++ { err := g.fillAny(slice.Index(i)) if err != nil { return err @@ -225,7 +230,7 @@ func (g *Generator) GenerateUInt32() (uint32, error) { } func (g *Generator) GenerateString() (string, error) { - maxStrLength := uint32(2000000) + maxStrLength := uint32(1000) if g.position >= g.dataSize { return "nil", errors.New("the data bytes are over") @@ -235,10 +240,7 @@ func (g *Generator) GenerateString() (string, error) { if err != nil { return "nil", errors.New("the data bytes are over") } - - if g.position > maxStrLength { - return "nil", errors.New("the string length too large") - } + length = length % maxStrLength startBytePos := g.position if startBytePos >= g.dataSize {