afl-capi.rs 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. extern crate mp4parse;
  2. use mp4parse::*;
  3. #[cfg(feature = "fuzz")]
  4. #[macro_use]
  5. extern crate abort_on_panic;
  6. use std::io::Read;
  7. extern fn vec_read(buf: *mut u8, size: usize, userdata: *mut std::os::raw::c_void) -> isize {
  8. let mut input: &mut std::io::Cursor<Vec<u8>> = unsafe { &mut *(userdata as *mut _) };
  9. let mut buf = unsafe { std::slice::from_raw_parts_mut(buf, size) };
  10. match input.read(&mut buf) {
  11. Ok(n) => n as isize,
  12. Err(_) => -1,
  13. }
  14. }
  15. fn doit() {
  16. let mut input = Vec::new();
  17. std::io::stdin().read_to_end(&mut input).unwrap();
  18. let mut cursor = std::io::Cursor::new(input);
  19. let io = mp4parse_io { read: vec_read, userdata: &mut cursor as *mut _ as *mut std::os::raw::c_void };
  20. unsafe {
  21. let context = mp4parse_new(&io);
  22. let rv = mp4parse_read(context);
  23. if rv == mp4parse_error::MP4PARSE_OK {
  24. for track in 0..mp4parse_get_track_count(context) {
  25. let mut info = mp4parse_track_info {
  26. track_type: mp4parse_track_type::MP4PARSE_TRACK_TYPE_VIDEO,
  27. track_id: 0,
  28. duration: 0,
  29. media_time: 0,
  30. };
  31. let rv = mp4parse_get_track_info(context, track, &mut info);
  32. if rv == mp4parse_error::MP4PARSE_OK {
  33. println!("track {}: id={} duration={} media_time={}",
  34. track, info.track_id, info.duration, info.media_time);
  35. match info.track_type {
  36. mp4parse_track_type::MP4PARSE_TRACK_TYPE_VIDEO => {
  37. let mut video = mp4parse_track_video_info {
  38. display_width: 0,
  39. display_height: 0,
  40. image_width: 0,
  41. image_height: 0,
  42. };
  43. let rv = mp4parse_get_track_video_info(context, track, &mut video);
  44. if rv == mp4parse_error::MP4PARSE_OK {
  45. println!(" video: display={}x{} image={}x{}",
  46. video.display_width, video.display_height,
  47. video.image_width, video.image_height);
  48. }
  49. }
  50. mp4parse_track_type::MP4PARSE_TRACK_TYPE_AUDIO => {
  51. let mut audio = mp4parse_track_audio_info {
  52. channels: 0,
  53. bit_depth: 0,
  54. sample_rate: 0,
  55. };
  56. let rv = mp4parse_get_track_audio_info(context, track, &mut audio);
  57. if rv == mp4parse_error::MP4PARSE_OK {
  58. println!(" audio: channels={} bit_depth={} sample_rate={}",
  59. audio.channels, audio.bit_depth, audio.sample_rate);
  60. }
  61. }
  62. }
  63. }
  64. }
  65. } else if rv == mp4parse_error::MP4PARSE_ERROR_ASSERT {
  66. panic!("wrapper thread caught panic");
  67. }
  68. mp4parse_free(context);
  69. }
  70. }
  71. #[cfg(feature = "fuzz")]
  72. fn main() {
  73. abort_on_panic!({
  74. doit();
  75. });
  76. }
  77. #[cfg(not(feature = "fuzz"))]
  78. fn main() {
  79. doit();
  80. }