diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-03-24 00:20:05 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-03-24 00:32:18 +0100 |
commit | 59a4b73531428d2f420b4dad545172c8483ced0f (patch) | |
tree | babb12b764acdbba333a9b29a31a6e9c406e7342 /libavcodec/pthread.c | |
parent | 71c2a70cbfbb5fea6dffa5e462b0227565e29bcc (diff) | |
download | ffmpeg-59a4b73531428d2f420b4dad545172c8483ced0f.tar.gz |
pthread/mpegvideo: detect and block attempts to init frames after setup.
This fixes race conditions that ultimately lead to memory corruption.
Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/pthread.c')
-rw-r--r-- | libavcodec/pthread.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index 7834922f9f..d8f8858c1e 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -932,6 +932,17 @@ static int *allocate_progress(PerThreadContext *p) return p->progress[i]; } +int ff_thread_can_start_frame(AVCodecContext *avctx) +{ + PerThreadContext *p = avctx->thread_opaque; + if ((avctx->active_thread_type&FF_THREAD_FRAME) && p->state != STATE_SETTING_UP && + (avctx->codec->update_thread_context || (!avctx->thread_safe_callbacks && + avctx->get_buffer != avcodec_default_get_buffer))) { + return 0; + } + return 1; +} + int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f) { PerThreadContext *p = avctx->thread_opaque; |