History

avcodec/vp3: Simplify shuffling frames, fix crash on alloc error

When decoding non-keyframes, the decoding process expects there to be two reference frames, the last one and the golden one. The existence of the golden one is checked and in case it is there, it is presumed that the last one exists as well. This assumption is wrong in case of memory allocation failure, namely in case the call to ff_thread_ref_frame() that sets the last frame fails. Fix this by actually performing a shuffle without creating new references. This can't fail and has the advantage of fewer implicit allocations.

Andreas Rheinhardt committed 3 years ago

Commit 0e6fdeb1 parent 3614f7e1 file · +3 −8Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/vp3.c+3−8
@@ -2498,19 +2498,14 @@ static int update_frames(AVCodecContext *avctx) · 2497 unmodified lines
2498 Vp3DecodeContext *s = avctx->priv_data;2498 Vp3DecodeContext *s = avctx->priv_data;
2499 int ret = 0;2499 int ret = 0;
2500 2500
2501 /* shuffle frames (last = current) */
2502 ff_thread_release_ext_buffer(avctx, &s->last_frame);
2503 ret = ff_thread_ref_frame(&s->last_frame, &s->current_frame);
2504 if (ret < 0)
2505 goto fail;
2506
2507 if (s->keyframe) {2501 if (s->keyframe) {
2508 ff_thread_release_ext_buffer(avctx, &s->golden_frame);2502 ff_thread_release_ext_buffer(avctx, &s->golden_frame);
2509 ret = ff_thread_ref_frame(&s->golden_frame, &s->current_frame);2503 ret = ff_thread_ref_frame(&s->golden_frame, &s->current_frame);
2510 }2504 }
2505 /* shuffle frames */
2506 ff_thread_release_ext_buffer(avctx, &s->last_frame);
2507 FFSWAP(ThreadFrame, s->last_frame, s->current_frame);
2511 2508
2512fail:
2513 ff_thread_release_ext_buffer(avctx, &s->current_frame);
2514 return ret;2509 return ret;
2515}2510}
2516 2511

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t