patch-layer12_c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. --- libmad-0.15.1b.orig/layer12.c 2004-02-05 10:02:39.000000000 +0100
  2. +++ libmad-0.15.1b/layer12.c 2013-10-16 10:51:25.000000000 +0200
  3. @@ -134,6 +134,12 @@ int mad_layer_I(struct mad_stream *strea
  4. for (sb = 0; sb < bound; ++sb) {
  5. for (ch = 0; ch < nch; ++ch) {
  6. nb = mad_bit_read(&stream->ptr, 4);
  7. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  8. + {
  9. + stream->error = MAD_ERROR_LOSTSYNC;
  10. + stream->sync = 0;
  11. + return -1;
  12. + }
  13. if (nb == 15) {
  14. stream->error = MAD_ERROR_BADBITALLOC;
  15. @@ -146,6 +152,12 @@ int mad_layer_I(struct mad_stream *strea
  16. for (sb = bound; sb < 32; ++sb) {
  17. nb = mad_bit_read(&stream->ptr, 4);
  18. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  19. + {
  20. + stream->error = MAD_ERROR_LOSTSYNC;
  21. + stream->sync = 0;
  22. + return -1;
  23. + }
  24. if (nb == 15) {
  25. stream->error = MAD_ERROR_BADBITALLOC;
  26. @@ -162,6 +174,12 @@ int mad_layer_I(struct mad_stream *strea
  27. for (ch = 0; ch < nch; ++ch) {
  28. if (allocation[ch][sb]) {
  29. scalefactor[ch][sb] = mad_bit_read(&stream->ptr, 6);
  30. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  31. + {
  32. + stream->error = MAD_ERROR_LOSTSYNC;
  33. + stream->sync = 0;
  34. + return -1;
  35. + }
  36. # if defined(OPT_STRICT)
  37. /*
  38. @@ -187,6 +205,12 @@ int mad_layer_I(struct mad_stream *strea
  39. frame->sbsample[ch][s][sb] = nb ?
  40. mad_f_mul(I_sample(&stream->ptr, nb),
  41. sf_table[scalefactor[ch][sb]]) : 0;
  42. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  43. + {
  44. + stream->error = MAD_ERROR_LOSTSYNC;
  45. + stream->sync = 0;
  46. + return -1;
  47. + }
  48. }
  49. }
  50. @@ -195,6 +219,12 @@ int mad_layer_I(struct mad_stream *strea
  51. mad_fixed_t sample;
  52. sample = I_sample(&stream->ptr, nb);
  53. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  54. + {
  55. + stream->error = MAD_ERROR_LOSTSYNC;
  56. + stream->sync = 0;
  57. + return -1;
  58. + }
  59. for (ch = 0; ch < nch; ++ch) {
  60. frame->sbsample[ch][s][sb] =
  61. @@ -403,7 +433,15 @@ int mad_layer_II(struct mad_stream *stre
  62. nbal = bitalloc_table[offsets[sb]].nbal;
  63. for (ch = 0; ch < nch; ++ch)
  64. + {
  65. allocation[ch][sb] = mad_bit_read(&stream->ptr, nbal);
  66. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  67. + {
  68. + stream->error = MAD_ERROR_LOSTSYNC;
  69. + stream->sync = 0;
  70. + return -1;
  71. + }
  72. + }
  73. }
  74. for (sb = bound; sb < sblimit; ++sb) {
  75. @@ -411,6 +449,13 @@ int mad_layer_II(struct mad_stream *stre
  76. allocation[0][sb] =
  77. allocation[1][sb] = mad_bit_read(&stream->ptr, nbal);
  78. +
  79. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  80. + {
  81. + stream->error = MAD_ERROR_LOSTSYNC;
  82. + stream->sync = 0;
  83. + return -1;
  84. + }
  85. }
  86. /* decode scalefactor selection info */
  87. @@ -419,6 +464,12 @@ int mad_layer_II(struct mad_stream *stre
  88. for (ch = 0; ch < nch; ++ch) {
  89. if (allocation[ch][sb])
  90. scfsi[ch][sb] = mad_bit_read(&stream->ptr, 2);
  91. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  92. + {
  93. + stream->error = MAD_ERROR_LOSTSYNC;
  94. + stream->sync = 0;
  95. + return -1;
  96. + }
  97. }
  98. }
  99. @@ -442,6 +493,12 @@ int mad_layer_II(struct mad_stream *stre
  100. for (ch = 0; ch < nch; ++ch) {
  101. if (allocation[ch][sb]) {
  102. scalefactor[ch][sb][0] = mad_bit_read(&stream->ptr, 6);
  103. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  104. + {
  105. + stream->error = MAD_ERROR_LOSTSYNC;
  106. + stream->sync = 0;
  107. + return -1;
  108. + }
  109. switch (scfsi[ch][sb]) {
  110. case 2:
  111. @@ -452,11 +509,23 @@ int mad_layer_II(struct mad_stream *stre
  112. case 0:
  113. scalefactor[ch][sb][1] = mad_bit_read(&stream->ptr, 6);
  114. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  115. + {
  116. + stream->error = MAD_ERROR_LOSTSYNC;
  117. + stream->sync = 0;
  118. + return -1;
  119. + }
  120. /* fall through */
  121. case 1:
  122. case 3:
  123. scalefactor[ch][sb][2] = mad_bit_read(&stream->ptr, 6);
  124. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  125. + {
  126. + stream->error = MAD_ERROR_LOSTSYNC;
  127. + stream->sync = 0;
  128. + return -1;
  129. + }
  130. }
  131. if (scfsi[ch][sb] & 1)
  132. @@ -488,6 +557,12 @@ int mad_layer_II(struct mad_stream *stre
  133. index = offset_table[bitalloc_table[offsets[sb]].offset][index - 1];
  134. II_samples(&stream->ptr, &qc_table[index], samples);
  135. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  136. + {
  137. + stream->error = MAD_ERROR_LOSTSYNC;
  138. + stream->sync = 0;
  139. + return -1;
  140. + }
  141. for (s = 0; s < 3; ++s) {
  142. frame->sbsample[ch][3 * gr + s][sb] =
  143. @@ -506,6 +581,12 @@ int mad_layer_II(struct mad_stream *stre
  144. index = offset_table[bitalloc_table[offsets[sb]].offset][index - 1];
  145. II_samples(&stream->ptr, &qc_table[index], samples);
  146. + if (mad_bit_nextbyte(&stream->ptr) > stream->next_frame)
  147. + {
  148. + stream->error = MAD_ERROR_LOSTSYNC;
  149. + stream->sync = 0;
  150. + return -1;
  151. + }
  152. for (ch = 0; ch < nch; ++ch) {
  153. for (s = 0; s < 3; ++s) {