Skip to content

Commit

Permalink
threading: Ensure passing the correct retval to decode_frame_exit
Browse files Browse the repository at this point in the history
We must reload error just before calling dav1d_decode_frame_exit, as
it may have become stale between the last load and that call.
This can result in crashes since we signal a seemingly successfully decoded
frame, when it's not.
Reloading error within the frame done condition's body ensures a non-stale
value, as we use 'f->task_thread.task_counter == 0' to ensure all other
threads / tasks have already completed when entering it. In other words, only
the last thread still working on this frame can execute this code, after
all other threads have returned to doing something else.
  • Loading branch information
Victorien Le Couviour--Tuffet authored and Frank Bossen committed Oct 21, 2023
1 parent e24f330 commit 37e3c0b
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/thread_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ void *dav1d_worker_task(void *data) {
atomic_load(&f->task_thread.done[0]) &&
(!uses_2pass || atomic_load(&f->task_thread.done[1])))
{
error = atomic_load(&f->task_thread.error);
dav1d_decode_frame_exit(f, error == 1 ? DAV1D_ERR(EINVAL) :
error ? DAV1D_ERR(ENOMEM) : 0);
f->n_tile_data = 0;
Expand Down Expand Up @@ -889,6 +890,7 @@ void *dav1d_worker_task(void *data) {
if (!num_tasks && atomic_load(&f->task_thread.done[0]) &&
atomic_load(&f->task_thread.done[1]))
{
error = atomic_load(&f->task_thread.error);
dav1d_decode_frame_exit(f, error == 1 ? DAV1D_ERR(EINVAL) :
error ? DAV1D_ERR(ENOMEM) : 0);
f->n_tile_data = 0;
Expand Down Expand Up @@ -918,6 +920,7 @@ void *dav1d_worker_task(void *data) {
if (!num_tasks && atomic_load(&f->task_thread.done[0]) &&
(!uses_2pass || atomic_load(&f->task_thread.done[1])))
{
error = atomic_load(&f->task_thread.error);
dav1d_decode_frame_exit(f, error == 1 ? DAV1D_ERR(EINVAL) :
error ? DAV1D_ERR(ENOMEM) : 0);
f->n_tile_data = 0;
Expand Down

0 comments on commit 37e3c0b

Please sign in to comment.