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

Function stringInsertionPoints

json_fuzz_test.go:782–797  ·  view source on GitHub ↗

stringInsertionPoints returns the byte positions of all unescaped closing '"' chars that terminate a string body in data. Used by mutation operators that need to inject bytes inside a JSON string. The simple scanner does not track `\\` sequences perfectly (e.g. `\\"`), but it is good enough for fuzz

(data []byte)

Source from the content-addressed store, hash-verified

780// not track `\\` sequences perfectly (e.g. `\\"`), but it is good enough
781// for fuzz-targeted injection.
782func stringInsertionPoints(data []byte) []int {
783 var pos []int
784 inStr := false
785 for i := 1; i < len(data); i++ {
786 if data[i] != '"' || data[i-1] == '\\' {
787 continue
788 }
789 if !inStr {
790 inStr = true
791 } else {
792 pos = append(pos, i) // just before the closing quote
793 inStr = false
794 }
795 }
796 return pos
797}
798
799// injectInvalidUTF8 inserts a raw invalid-UTF-8 byte sequence inside a JSON
800// string value. Targets the parser's UTF-8 validation path: the parser must

Callers 2

injectInvalidUTF8Function · 0.85
injectLoneSurrogateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected