README.md
1# Fuzzer for libFLAC decoder
2
3## Plugin Design Considerations
4The fuzzer plugin for FLAC decoder is designed based on the understanding of the
5codec and tries to achieve the following:
6
7##### Maximize code coverage
8The configuration parameters are not hardcoded, but instead selected based on
9incoming data. This ensures more code paths are reached by the fuzzer.
10
11FLAC supports the following two decoder API's for native mode:
121. FLAC__stream_decoder_process_single (frame by frame decoding)
132. FLAC__stream_decoder_process_until_end_of_stream (decoding entire stream)
14
15One of these two decoder API's will be called based on LSB of 5th byte of data.
16
17This also ensures that the plugin is always deterministic for any given input.
18
19##### Maximize utilization of input data
20The plugin feeds the input data to the codec using a read_callback as and when
21requested by the decoder. The read_callback feeds the input data to the decoder
22until the end of stream.
23
24This ensures that the plugin tolerates any kind of input (empty, huge,
25malformed, etc) and doesnt `exit()` on any input and thereby increasing the
26chance of identifying vulnerabilities.
27
28## Build
29
30This describes steps to build flac_dec_fuzzer binary.
31
32### Android
33
34#### Steps to build
35Build the fuzzer
36```
37 $ mm -j$(nproc) flac_dec_fuzzer
38```
39
40#### Steps to run
41Create a directory CORPUS_DIR and copy some flac files to that folder
42Push this directory to device.
43
44To run on device
45```
46 $ adb sync data
47 $ adb shell /data/fuzz/arm64/flac_dec_fuzzer/flac_dec_fuzzer CORPUS_DIR
48```
49To run on host
50```
51 $ $ANDROID_HOST_OUT/fuzz/x86_64/flac_dec_fuzzer/flac_dec_fuzzer CORPUS_DIR
52```
53
54# Fuzzer for libFLAC encoder
55
56## Plugin Design Considerations
57The fuzzer plugin for flac encoder is designed based on the understanding of the
58codec and tries to achieve the following:
59
60##### Maximize code coverage
61
62The configuration parameters are not hardcoded, but instead selected based on
63incoming data. This ensures more code paths are reached by the fuzzer.
64
65Follwing functions were called in initEncoder to configure the encoder:
66
67| Function name | Parameter| Valid Values| Configured Value|
68|------------- |------------- |-------------| ----- |
69| `FLAC__stream_encoder_set_sample_rate` | sampleRate |`1 ` to `655350 ` | All the bits of 1st, 2nd and 3rd byte of data |
70| `FLAC__stream_encoder_set_channels` | mChannels |`1 ` `2 ` | bit 0 of 4th byte of data |
71| `FLAC__stream_encoder_set_compression_level` | compression |`1 ` `2 ` | bit 0 of 5th byte of data |
72| `FLAC__stream_encoder_set_bits_per_sample` | bitsPerSample |`16 ` `24 ` | bit 0 of 6th byte of data |
73| `FLAC__stream_encoder_set_verify` | - |`false ` `true ` | bit 0 of 7th byte of data |
74| `FLAC__stream_encoder_set_streamable_subset` | - |`false ` `true ` | bit 0 of 8th byte of data |
75| `FLAC__stream_encoder_set_do_mid_side_stereo` | - |`false ` `true ` | bit 0 of 9th byte of data |
76| `FLAC__stream_encoder_set_loose_mid_side_stereo` | - |`false ` `true ` | bit 0 of 10th byte of data |
77| `FLAC__stream_encoder_set_max_lpc_order` | - |`false ` `true ` | bit 0 of 11th byte of data|
78| `FLAC__stream_encoder_set_qlp_coeff_precision` | - |`0 ` `1 ` | bit 0 of 12th byte of data |
79| `FLAC__stream_encoder_set_do_qlp_coeff_prec_search` | - |`false ` `true ` | bit 0 of 13th byte of data |
80| `FLAC__stream_encoder_set_do_escape_coding` | - |`false ` `true ` | bit 0 of 14th byte of data|
81| `FLAC__stream_encoder_set_do_exhaustive_model_search` | - |`false ` `true ` | bit 0 of 15th byte of data |
82| `FLAC__stream_encoder_set_min_residual_partition_order` | - |`0 ` `1 ` | bit 0 of 16th byte of data |
83| `FLAC__stream_encoder_set_max_residual_partition_order` | - |`0 ` `1 ` | bit 0 of 17th byte of data |
84| `FLAC__stream_encoder_set_rice_parameter_search_dist` | - |`0 ` `1 ` | bit 0 of 18th byte of data|
85| `FLAC__stream_encoder_set_total_samples_estimate` | - |`0 ` `1 ` | bit 0 of 19th byte of data|
86
87
88##### Maximize utilization of input data
89The plugin feeds the entire input data to the codec and continues with the encoding even on a failure. This ensures that the plugin tolerates any kind of input (empty, huge, malformed, etc) and doesn't `exit()` on any input and thereby increasing the chance of identifying vulnerabilities.
90
91## Build
92
93This describes steps to build flac_enc_fuzzer binary.
94
95## Android
96
97### Steps to build
98Build the fuzzer
99```
100 $ mm -j$(nproc) flac_enc_fuzzer
101```
102
103### Steps to run
104Create a directory CORPUS_DIR and copy some wav files to that folder.
105Push this directory to device.
106
107To run on device
108```
109 $ adb sync data
110 $ adb shell /data/fuzz/arm64/flac_enc_fuzzer/flac_enc_fuzzer CORPUS_DIR
111```
112To run on host
113```
114 $ $ANDROID_HOST_OUT/fuzz/x86_64/flac_enc_fuzzer/flac_enc_fuzzer CORPUS_DIR
115```
116
117## References:
118 * http://llvm.org/docs/LibFuzzer.html
119 * https://github.com/google/oss-fuzz
120