Skip to content

Commit

Permalink
x264: Patch to prevent use after free
Browse files Browse the repository at this point in the history
  • Loading branch information
Elias Carotti authored and nacho committed Nov 6, 2023
1 parent 23d28db commit 5c5120d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
From fa08eaac46d1a94c2b8c93627f7664dc7358e6e1 Mon Sep 17 00:00:00 2001
From: Elias Carotti <eliascrt _at_ amazon _dot_ it>
Date: Mon, 11 Sep 2023 12:03:24 +0200
Subject: [PATCH] Prevent mb_info_free to be called before all threads are done
using mb_info

---
encoder/encoder.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/encoder/encoder.c b/encoder/encoder.c
index 39d7ac8f..7b5fbb00 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -3108,11 +3108,15 @@ cont:
/* Do hpel now */
for( int mb_y = h->i_threadslice_start; mb_y <= h->i_threadslice_end; mb_y++ )
fdec_filter_row( h, mb_y, 1 );
- x264_threadslice_cond_broadcast( h, 2 );
- /* Do the first row of hpel, now that the previous slice is done */
- if( h->i_thread_idx > 0 )
+
+ if( h->i_thread_idx == 0 ) {
+ x264_threadslice_cond_broadcast( h, 2 );
+ }
+ else
{
x264_threadslice_cond_wait( h->thread[h->i_thread_idx-1], 2 );
+ x264_threadslice_cond_broadcast( h, 2 );
+ /* Do the first row of hpel, now that the previous slice is done */
fdec_filter_row( h, h->i_threadslice_start + (1 << SLICE_MBAFF), 2 );
}
}
--
2.34.1

3 changes: 3 additions & 0 deletions gvsbuild/projects/x264.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def __init__(self):
fetch_submodules=False,
dependencies=["nasm", "msys2"],
tag="31e19f92f00c7003fa115047ce50978bc98c3a0d",
patches=[
"x264-0001-Prevent-mb_info_free-to-be-called-before-all-threads.patch",
],
)

def build(self):
Expand Down

0 comments on commit 5c5120d

Please sign in to comment.