Add length limits 50 for silces and chans and 1000 for strings

This commit is contained in:
Pavel Pertsev 2024-06-05 11:13:24 +03:00
parent 525e73b00c
commit e443049df9

View file

@ -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 {