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
24982498 Vp3DecodeContext *s = avctx->priv_data;
24992499 int ret = 0;
25002500
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−
25072501 if (s->keyframe) {
25082502 ff_thread_release_ext_buffer(avctx, &s->golden_frame);
25092503 ret = ff_thread_ref_frame(&s->golden_frame, &s->current_frame);
25102504 }
2505+ /* shuffle frames */
2506+ ff_thread_release_ext_buffer(avctx, &s->last_frame);
2507+ FFSWAP(ThreadFrame, s->last_frame, s->current_frame);
25112508
2512−fail:
2513− ff_thread_release_ext_buffer(avctx, &s->current_frame);
25142509 return ret;
25152510 }
25162511

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