MCPcopy Create free account
hub / github.com/buger/jsonparser / byteflipAtStructuralByte

Function byteflipAtStructuralByte

json_fuzz_test.go:764–775  ·  view source on GitHub ↗

byteflipAtStructuralByte flips a byte at a structural position ({, }, [, ], :, ,, "). This corrupts the document skeleton, exercising the parser's malformed-structure detection paths.

(r *rand.Rand, data []byte)

Source from the content-addressed store, hash-verified

762// ], :, ,, "). This corrupts the document skeleton, exercising the parser's
763// malformed-structure detection paths.
764func byteflipAtStructuralByte(r *rand.Rand, data []byte) []byte {
765 pos := findStructuralBytes(data, '{', '}', '[', ']', ':', ',', '"')
766 if len(pos) == 0 {
767 return data
768 }
769 idx := pos[r.Intn(len(pos))]
770 out := make([]byte, len(data))
771 copy(out, data)
772 // XOR with a nonzero mask to guarantee the byte changes.
773 out[idx] ^= byte(1 + r.Intn(255))
774 return out
775}
776
777// stringInsertionPoints returns the byte positions of all unescaped closing
778// '"' chars that terminate a string body in data. Used by mutation operators

Callers

nothing calls this directly

Calls 1

findStructuralBytesFunction · 0.85

Tested by

no test coverage detected