| 1 |
# valid |
| 2 |
|
| 3 |
This program is a helper to check the output of `utf8.Valid` facilitate |
| 4 |
debugging. It accepts some input, runs both this library and stdlib's version of |
| 5 |
`utf8.Valid`, and prints out the result. |
| 6 |
|
| 7 |
## Usage |
| 8 |
|
| 9 |
Provide the input as the the first argument to the program: |
| 10 |
|
| 11 |
``` |
| 12 |
$ go run main.go "hello! 😊" |
| 13 |
hello! 😊 |
| 14 |
[104 101 108 108 111 33 32 240 159 152 138] |
| 15 |
11 bytes |
| 16 |
stdlib: utf8: true ascii: false |
| 17 |
valid: utf8: true ascii: false v: 1 |
| 18 |
``` |
| 19 |
|
| 20 |
The input is parsed as a double quoted Go string, so you can use escape codes: |
| 21 |
|
| 22 |
``` |
| 23 |
$ go run main.go "\xFA" |
| 24 |
|
| 25 |
[250] |
| 26 |
1 bytes |
| 27 |
stdlib: utf8: false ascii: false |
| 28 |
valid: utf8: false ascii: false v: 0 |
| 29 |
``` |
| 30 |
|
| 31 |
Alternatively it can also conusme input from stdin: |
| 32 |
|
| 33 |
``` |
| 34 |
$ cat example.txt |
| 35 |
hello! 😊 |
| 36 |
$ go run main.go < example.txt |
| 37 |
hello! 😊 |
| 38 |
|
| 39 |
[104 101 108 108 111 33 32 240 159 152 138 10] |
| 40 |
12 bytes |
| 41 |
stdlib: utf8: true ascii: false |
| 42 |
valid: utf8: true ascii: false v: 1 |
| 43 |
``` |
| 44 |
|
| 45 |
As a bonus, if the file is the result of a failure reported by Go 1.18 fuzz, the |
| 46 |
program extracts the actual value of the test: |
| 47 |
|
| 48 |
``` |
| 49 |
$ cat fuzz.out |
| 50 |
go test fuzz |
| 51 |
[]byte("000000000000000000~\xFF") |
| 52 |
$ go run main.go < fuzz.out |
| 53 |
Got fuzzer input |
| 54 |
000000000000000000~ |
| 55 |
[48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 126 255] |
| 56 |
20 bytes |
| 57 |
stdlib: utf8: false ascii: false |
| 58 |
valid: utf8: false ascii: false v: 0 |
| 59 |
``` |
| 60 |
|
| 61 |
## GDB |
| 62 |
|
| 63 |
A useful way to debug is to run this program with some problematic input and use |
| 64 |
GDB to step through the execution and inspect registers. The `debug.gdb` file is |
| 65 |
a basic helper to automate part of the process. For example: |
| 66 |
|
| 67 |
``` |
| 68 |
$ go build main.go && gdb --command=debug.gdb -ex "set args < ./example.txt" ./main |
| 69 |
``` |