1# Fuzzer for libstagefright_amrnbdec decoder 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-NB supports the following parameters: 121. Stream format (parameter name: `input_format`) 132. 3GPP frame type (parameter name: `frame_type`) 14 15| Parameter| Valid Values| Configured Value| 16|------------- |-------------| ----- | 17| `input_format` | 0. `MIME_IETF` 1. `IF2` | Bit 0 (LSB) of 1st byte of data. | 18| `frame_type` | 0. `AMR_475` 1. `AMR_515` 2. `AMR_59` 3. `AMR_67` 4. `AMR_74` 5. `AMR_795` 6. `AMR_102` 7. `AMR_122` | Bits 3, 4 and 5 of 1st byte of data. | 19 20 21This also ensures that the plugin is always deterministic for any given input. 22 23##### Maximize utilization of input data 24The plugin feeds the entire input data to the codec using a loop. 25If the decode operation was successful, the input is advanced by the frame size 26which is based on `input_format` and `frame_type` selected. 27If the decode operation was un-successful, the input is still advanced by frame size so 28that the fuzzer can proceed to feed the next frame. 29 30This ensures that the plugin tolerates any kind of input (empty, huge, 31malformed, etc) and doesnt `exit()` on any input and thereby increasing the 32chance of identifying vulnerabilities. 33 34## Build 35 36This describes steps to build amrnb_dec_fuzzer binary. 37 38### Android 39 40#### Steps to build 41Build the fuzzer 42``` 43 $ mm -j$(nproc) amrnb_dec_fuzzer 44``` 45 46#### Steps to run 47Create a directory CORPUS_DIR and copy some amrnb files to that folder 48Push this directory to device. 49 50To run on device 51``` 52 $ adb sync data 53 $ adb shell /data/fuzz/arm64/amrnb_dec_fuzzer/amrnb_dec_fuzzer CORPUS_DIR 54``` 55To run on host 56``` 57 $ $ANDROID_HOST_OUT/fuzz/x86_64/amrnb_dec_fuzzer/amrnb_dec_fuzzer CORPUS_DIR 58``` 59 60## References: 61 * http://llvm.org/docs/LibFuzzer.html 62 * https://github.com/google/oss-fuzz 63