1# Fuzzer for libmediatranscoder 2 3## Plugin Design Considerations 4The fuzzer plugin for libmediatranscoder is designed based on the understanding of the 5transcoder 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 11Transcoder supports the following parameters: 121. Destination Mime Type (parameter name: `dstMime`) 132. AVC Profile (parameter name: `profile`) 143. HEVC Profile (parameter name: `profile`) 154. AVC Level (parameter name: `level`) 165. HEVC Level (parameter name: `level`) 176. Bitrate (parameter name: `bitrate`) 18 19| Parameter| Valid Values| Configured Value| 20|------------- |-------------| ----- | 21| `dstMime` | 0. `AMEDIA_MIMETYPE_VIDEO_AVC` 1. `AMEDIA_MIMETYPE_VIDEO_HEVC` | Bit 0 (LSB) of 1st byte of data | 22| `profile` for AVC | 0. `PROFILE_AVC_BASELINE` 1. `PROFILE_AVC_CONSTRAINED_BASELINE` 2. `PROFILE_AVC_MAIN`| All bits of 2nd byte of data modulus 3 | 23| `profile` for HEVC | 0. `PROFILE_HEVC_MAIN` 1. `PROFILE_HEVC_MAIN_STILL` | All bits of 2nd byte of data modulus 2 | 24| `level` for AVC | 0. `LEVEL_AVC_1` 1. `LEVEL_AVC_1B` 2. `LEVEL_AVC_1_1` 3. `LEVEL_AVC_1_2` 4. `LEVEL_AVC_1_3` 5. `LEVEL_AVC_2` 6. `LEVEL_AVC_2_1` 7. `LEVEL_AVC_2_2` 8. `LEVEL_AVC_3` 9. `LEVEL_AVC_3_1` 10. `LEVEL_AVC_3_2` 11. `LEVEL_AVC_4` 12. `LEVEL_AVC_4_1` 13. `LEVEL_AVC_4_2` 14. `LEVEL_AVC_5`| All bits of 3rd byte of data modulus 15 | 25| `level` for HEVC | 0. `LEVEL_HEVC_MAIN_1` 1. `LEVEL_HEVC_MAIN_2` 2. `LEVEL_HEVC_MAIN_2_1` 3. `LEVEL_HEVC_MAIN_3` 4. `LEVEL_HEVC_MAIN_3_1` 5. `LEVEL_HEVC_MAIN_4` 6. `LEVEL_HEVC_MAIN_4_1` 7. `LEVEL_HEVC_MAIN_5` 8. `LEVEL_HEVC_MAIN_5_1` 9. `LEVEL_HEVC_MAIN_5_2` | All bits of 3rd byte of data modulus 10 | 26| `bitrate` | In the range `0` to `500000000` | All bits of 4th and 5th byte of data | 27 28This also ensures that the plugin is always deterministic for any given input. 29##### Maximize utilization of input data 30The plugin feeds the entire input data to the transcoder. 31This ensures that the plugin tolerates any kind of input (empty, huge, 32malformed, etc) and doesnt `exit()` on any input and thereby increasing the 33chance of identifying vulnerabilities. 34 35## Build 36 37This describes steps to build media_transcoder_fuzzer binary. 38 39### Android 40 41#### Steps to build 42Build the fuzzer 43``` 44 $ mm -j$(nproc) media_transcoder_fuzzer 45``` 46#### Steps to run 47Create a directory CORPUS_DIR 48``` 49 $ adb shell mkdir CORPUS_DIR 50``` 51To run on device 52``` 53 $ adb sync data 54 $ adb shell /data/fuzz/${TARGET_ARCH}/media_transcoder_fuzzer/media_transcoder_fuzzer CORPUS_DIR 55``` 56 57## References: 58 * http://llvm.org/docs/LibFuzzer.html 59 * https://github.com/google/oss-fuzz 60