2
0

xiph.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (C) 2007 The FFmpeg Project
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/intreadwrite.h"
  21. #include "xiph.h"
  22. int avpriv_split_xiph_headers(const uint8_t *extradata, int extradata_size,
  23. int first_header_size, const uint8_t *header_start[3],
  24. int header_len[3])
  25. {
  26. int i;
  27. if (extradata_size >= 6 && AV_RB16(extradata) == first_header_size) {
  28. int overall_len = 6;
  29. for (i=0; i<3; i++) {
  30. header_len[i] = AV_RB16(extradata);
  31. extradata += 2;
  32. header_start[i] = extradata;
  33. extradata += header_len[i];
  34. if (overall_len > extradata_size - header_len[i])
  35. return -1;
  36. overall_len += header_len[i];
  37. }
  38. } else if (extradata_size >= 3 && extradata_size < INT_MAX - 0x1ff && extradata[0] == 2) {
  39. int overall_len = 3;
  40. extradata++;
  41. for (i=0; i<2; i++, extradata++) {
  42. header_len[i] = 0;
  43. for (; overall_len < extradata_size && *extradata==0xff; extradata++) {
  44. header_len[i] += 0xff;
  45. overall_len += 0xff + 1;
  46. }
  47. header_len[i] += *extradata;
  48. overall_len += *extradata;
  49. if (overall_len > extradata_size)
  50. return -1;
  51. }
  52. header_len[2] = extradata_size - overall_len;
  53. header_start[0] = extradata;
  54. header_start[1] = header_start[0] + header_len[0];
  55. header_start[2] = header_start[1] + header_len[1];
  56. } else {
  57. return -1;
  58. }
  59. return 0;
  60. }