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

Function injectMismatchedCloser

json_fuzz_test.go:911–925  ·  view source on GitHub ↗

injectMismatchedCloser swaps a closing '}' for ']' (or vice versa). The grammar generator always pairs '{' with '}' and '[' with ']'; this operator produces the cross-type mismatch class ([{...}] → [{...]}) that stresses blockEnd's open/close pairing logic.

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

Source from the content-addressed store, hash-verified

909// operator produces the cross-type mismatch class ([{...}] → [{...]}) that
910// stresses blockEnd's open/close pairing logic.
911func injectMismatchedCloser(r *rand.Rand, data []byte) []byte {
912 closers := findStructuralBytes(data, '}', ']')
913 if len(closers) == 0 {
914 return data
915 }
916 idx := closers[r.Intn(len(closers))]
917 out := make([]byte, len(data))
918 copy(out, data)
919 if out[idx] == '}' {
920 out[idx] = ']'
921 } else {
922 out[idx] = '}'
923 }
924 return out
925}
926
927// =============================================================================
928// Adversarial key-path generator

Callers

nothing calls this directly

Calls 1

findStructuralBytesFunction · 0.85

Tested by

no test coverage detected