| OLD | NEW |
| (Empty) | |
| 1 diff -wurp -N orig/libavcodec/get_bits.h ffmpeg/libavcodec/get_bits.h |
| 2 --- orig/libavcodec/get_bits.h 2011-07-12 20:47:45.164235088 -0700 |
| 3 +++ ffmpeg/libavcodec/get_bits.h 2011-07-12 20:47:45.252997950 -0700 |
| 4 @@ -52,9 +52,16 @@ |
| 5 /* buffer, buffer_end and size_in_bits must be present and used by every reader
*/ |
| 6 typedef struct GetBitContext { |
| 7 const uint8_t *buffer, *buffer_end; |
| 8 + /* Ugly, but clients of this bit reader do not seem to check for enough |
| 9 + * data before calling. So we'll return 0's on overrun rather than crashing |
| 10 + * with random read faults. |
| 11 + */ |
| 12 + int buffer_exhausted; |
| 13 + int buffer_enforcing; |
| 14 #ifdef ALT_BITSTREAM_READER |
| 15 int index; |
| 16 #elif defined A32_BITSTREAM_READER |
| 17 +#warning TODO - secure this against read overrun |
| 18 uint32_t *buffer_ptr; |
| 19 uint32_t cache0; |
| 20 uint32_t cache1; |
| 21 @@ -133,18 +140,26 @@ for examples see get_bits, show_bits, sk |
| 22 |
| 23 # ifdef ALT_BITSTREAM_READER_LE |
| 24 # define UPDATE_CACHE(name, gb) \ |
| 25 - name##_cache = AV_RL32(((const uint8_t *)(gb)->buffer)+(name##_index>>3)) >
> (name##_index&0x07) |
| 26 + if (!(gb)->buffer_exhausted)\ |
| 27 + name##_cache = AV_RL32(((const uint8_t *)(gb)->buffer)+(name##_index>>3
)) >> (name##_index&0x07);\ |
| 28 + else\ |
| 29 + name##_cache = 0; |
| 30 |
| 31 # define SKIP_CACHE(name, gb, num) name##_cache >>= (num) |
| 32 # else |
| 33 # define UPDATE_CACHE(name, gb) \ |
| 34 - name##_cache = AV_RB32(((const uint8_t *)(gb)->buffer)+(name##_index>>3)) <
< (name##_index&0x07) |
| 35 + if (!(gb)->buffer_exhausted)\ |
| 36 + name##_cache = AV_RB32(((const uint8_t *)(gb)->buffer)+(name##_index>>3
)) << (name##_index&0x07);\ |
| 37 + else\ |
| 38 + name##_cache = 0; |
| 39 |
| 40 # define SKIP_CACHE(name, gb, num) name##_cache <<= (num) |
| 41 # endif |
| 42 |
| 43 // FIXME name? |
| 44 -# define SKIP_COUNTER(name, gb, num) name##_index += (num) |
| 45 +# define SKIP_COUNTER(name, gb, num) name##_index += (num);\ |
| 46 + if ((gb)->buffer_enforcing && name##_index >= (gb)->size_in_bits)\ |
| 47 + (gb)->buffer_exhausted = 1;\ |
| 48 |
| 49 # define SKIP_BITS(name, gb, num) do { \ |
| 50 SKIP_CACHE(name, gb, num); \ |
| 51 @@ -172,6 +187,12 @@ static inline int get_bits_count(const G |
| 52 |
| 53 static inline void skip_bits_long(GetBitContext *s, int n){ |
| 54 s->index += n; |
| 55 + if (s->buffer_enforcing) { |
| 56 + if (n < 0 && s->index < s->size_in_bits) |
| 57 + s->buffer_exhausted = 0; |
| 58 + else if (s->index >= s->size_in_bits) |
| 59 + s->buffer_exhausted = 1; |
| 60 + } |
| 61 } |
| 62 |
| 63 #elif defined A32_BITSTREAM_READER |
| 64 @@ -301,7 +322,10 @@ static inline void skip_bits(GetBitConte |
| 65 } |
| 66 |
| 67 static inline unsigned int get_bits1(GetBitContext *s){ |
| 68 + if (s->buffer_exhausted) |
| 69 + return 0; |
| 70 #ifdef ALT_BITSTREAM_READER |
| 71 + { |
| 72 unsigned int index = s->index; |
| 73 uint8_t result = s->buffer[index>>3]; |
| 74 #ifdef ALT_BITSTREAM_READER_LE |
| 75 @@ -312,9 +336,12 @@ static inline unsigned int get_bits1(Get |
| 76 result >>= 8 - 1; |
| 77 #endif |
| 78 index++; |
| 79 + if (s->buffer_enforcing && index >= s->size_in_bits) |
| 80 + s->buffer_exhausted = 1; |
| 81 s->index = index; |
| 82 |
| 83 return result; |
| 84 + } |
| 85 #else |
| 86 return get_bits(s, 1); |
| 87 #endif |
| 88 @@ -392,6 +419,8 @@ static inline void init_get_bits(GetBitC |
| 89 s->buffer = buffer; |
| 90 s->size_in_bits = bit_size; |
| 91 s->buffer_end = buffer + buffer_size; |
| 92 + s->buffer_exhausted = 0; |
| 93 + s->buffer_enforcing = 0; |
| 94 #ifdef ALT_BITSTREAM_READER |
| 95 s->index = 0; |
| 96 #elif defined A32_BITSTREAM_READER |
| OLD | NEW |