1# Fuzzer for libstagefright_amrnbenc encoder 2 3## Plugin Design Considerations 4The fuzzer plugin for AMR-NB 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 11AMR-WB supports the following parameters: 121. Output Format (parameter name: `outputFormat`) 132. Mode (parameter name: `mode`) 14 15| Parameter| Valid Values| Configured Value| 16|------------- |-------------| ----- | 17| `outputFormat` | 0. `AMR_TX_WMF` 1. `AMR_TX_IF2` 2. `AMR_TX_ETS` | Bits 0, 1 and 2 of 1st byte of data. | 18| `mode` | 0. `MR475` 1. `MR515` 2. `MR59` 3. `MR67` 4. `MR74 ` 5. `MR795` 6. `MR102` 7. `MR122` 8. `MRDTX` | Bits 3, 4, 5 and 6 of 1st byte of data. | 19 20This also ensures that the plugin is always deterministic for any given input. 21 22##### Maximize utilization of input data 23The plugin feeds the entire input data to the codec using a loop. 24If the encode operation was successful, the input is advanced by the frame size. 25If the encode operation was un-successful, the input is still advanced by frame size so 26that the fuzzer can proceed to feed the next frame. 27 28This ensures that the plugin tolerates any kind of input (empty, huge, 29malformed, etc) and doesnt `exit()` on any input and thereby increasing the 30chance of identifying vulnerabilities. 31 32## Build 33 34This describes steps to build amrnb_enc_fuzzer binary. 35 36### Android 37 38#### Steps to build 39Build the fuzzer 40``` 41 $ mm -j$(nproc) amrnb_enc_fuzzer 42``` 43 44#### Steps to run 45Create a directory CORPUS_DIR and copy some pcm files to that folder 46Push this directory to device. 47 48To run on device 49``` 50 $ adb sync data 51 $ adb shell /data/fuzz/arm64/amrnb_enc_fuzzer/amrnb_enc_fuzzer CORPUS_DIR 52``` 53To run on host 54``` 55 $ $ANDROID_HOST_OUT/fuzz/x86_64/amrnb_enc_fuzzer/amrnb_enc_fuzzer CORPUS_DIR 56``` 57 58## References: 59 * http://llvm.org/docs/LibFuzzer.html 60 * https://github.com/google/oss-fuzz 61