[x264-devel] Fix invalid memcpy in sliced-threads

Jason Garrett-Glaser git at videolan.org
Mon May 20 23:06:46 CEST 2013


x264 | branch: master | Jason Garrett-Glaser <jason at x264.com> | Wed May  8 10:48:41 2013 -0700| [b1749e204d14087a768990e8bfe964d343e0b9a9] | committer: Jason Garrett-Glaser

Fix invalid memcpy in sliced-threads

Likely didn't actually break in practice, but memcpy with src==dst
is incorrect.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=b1749e204d14087a768990e8bfe964d343e0b9a9
---

 encoder/ratecontrol.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c
index 2157301..0fc7a0a 100644
--- a/encoder/ratecontrol.c
+++ b/encoder/ratecontrol.c
@@ -2593,14 +2593,16 @@ void x264_threads_distribute_ratecontrol( x264_t *h )
     if( h->i_frame == 0 )
         for( int i = 0; i < h->param.i_threads; i++ )
         {
-            x264_ratecontrol_t *t = h->thread[i]->rc;
-            memcpy( t->row_preds, rc->row_preds, sizeof(rc->row_preds) );
+            x264_t *t = h->thread[i];
+            if( t != h )
+                memcpy( t->rc->row_preds, rc->row_preds, sizeof(rc->row_preds) );
         }
 
     for( int i = 0; i < h->param.i_threads; i++ )
     {
         x264_t *t = h->thread[i];
-        memcpy( t->rc, rc, offsetof(x264_ratecontrol_t, row_pred) );
+        if( t != h )
+            memcpy( t->rc, rc, offsetof(x264_ratecontrol_t, row_pred) );
         t->rc->row_pred = &t->rc->row_preds[h->sh.i_type];
         /* Calculate the planned slice size. */
         if( rc->b_vbv && rc->frame_size_planned )



More information about the x264-devel mailing list