Skip to content

Commit

Permalink
fix bug with byte array input generation
Browse files Browse the repository at this point in the history
  • Loading branch information
anishnaik committed Jan 14, 2025
1 parent d9b5197 commit 5032f48
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions fuzzing/valuegeneration/generator_mutational.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,18 @@ func (g *MutationalValueGenerator) mutateBytesInternal(b []byte, length int) []b
}

// If we want a fixed-byte array and the mutated input is smaller than the requested length, then generate a random
// byte array
// TODO: This should be improved and maybe it is better to pad with zeros
// byte array and append it to the existing input
if length > 0 && len(input) < length {
return g.RandomValueGenerator.GenerateFixedBytes(length)
randomSlice := g.RandomValueGenerator.GenerateFixedBytes(length - len(input))
input = append(input, randomSlice...)
}

// Similarly, if we want a fixed-byte array and the mutated input is larger than the requested length, then truncate
// the array
if length > 0 && len(input) > length {
return input[:length]
}

return input
}

Expand Down

0 comments on commit 5032f48

Please sign in to comment.