Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame^] | 1 | gst-ffmpeg: avcodec/parser: reset indexes on realloc failure |
| 2 | |
| 3 | Fixes Ticket2982 |
| 4 | |
| 5 | Signed-off-by: Michael Niedermayer <michaelni@gmx.at> |
| 6 | (cherry picked from commit f31011e9abfb2ae75bb32bc44e2c34194c8dc40a) |
| 7 | |
| 8 | Signed-off-by: Michael Niedermayer <michaelni@gmx.at> |
| 9 | |
| 10 | Upstream-Status: Backport |
| 11 | |
| 12 | Signed-off-by: Yue Tao <yue.tao@windriver.com> |
| 13 | |
| 14 | --- |
| 15 | libavcodec/parser.c | 10 +++++++--- |
| 16 | 1 files changed, 7 insertions(+), 3 deletions(-) |
| 17 | |
| 18 | diff --git a/libavcodec/parser.c b/libavcodec/parser.c |
| 19 | index 2c6de6e..66eca06 100644 |
| 20 | --- a/gst-libs/ext/libav/libavcodec/parser.c |
| 21 | +++ b/gst-libs/ext/libav/libavcodec/parser.c |
| 22 | @@ -241,8 +241,10 @@ int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_s |
| 23 | if(next == END_NOT_FOUND){ |
| 24 | void* new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, (*buf_size) + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); |
| 25 | |
| 26 | - if(!new_buffer) |
| 27 | + if(!new_buffer) { |
| 28 | + pc->index = 0; |
| 29 | return AVERROR(ENOMEM); |
| 30 | + } |
| 31 | pc->buffer = new_buffer; |
| 32 | memcpy(&pc->buffer[pc->index], *buf, *buf_size); |
| 33 | pc->index += *buf_size; |
| 34 | @@ -255,9 +257,11 @@ int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_s |
| 35 | /* append to buffer */ |
| 36 | if(pc->index){ |
| 37 | void* new_buffer = av_fast_realloc(pc->buffer, &pc->buffer_size, next + pc->index + FF_INPUT_BUFFER_PADDING_SIZE); |
| 38 | - |
| 39 | - if(!new_buffer) |
| 40 | + if(!new_buffer) { |
| 41 | + pc->overread_index = |
| 42 | + pc->index = 0; |
| 43 | return AVERROR(ENOMEM); |
| 44 | + } |
| 45 | pc->buffer = new_buffer; |
| 46 | if (next > -FF_INPUT_BUFFER_PADDING_SIZE) |
| 47 | memcpy(&pc->buffer[pc->index], *buf, |
| 48 | -- |
| 49 | 1.7.5.4 |
| 50 | |