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)
| 780 | // not track `\\` sequences perfectly (e.g. `\\"`), but it is good enough |
| 781 | // for fuzz-targeted injection. |
| 782 | func 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 |
no outgoing calls
no test coverage detected