[Bf-blender-cvs] [53b98de2603] blender-v2.83-release: Fix T78867: Crash related to viewing video files

Sergey Sharybin noreply at git.blender.org
Wed Jul 29 10:53:12 CEST 2020


Commit: 53b98de26030574ae2ecdaac5e33b37acb5444e2
Author: Sergey Sharybin
Date:   Mon Jul 20 18:57:28 2020 +0200
Branches: blender-v2.83-release
https://developer.blender.org/rB53b98de26030574ae2ecdaac5e33b37acb5444e2

Fix T78867: Crash related to viewing video files

Any time FFmpeg was used to get a picture Blender would crash
when FFmpeg 4.3 is used. This affects thumbnails, VSE, Clip Editor.

Caused by a bug in FFmpeg which lead to crashes when unaligned
buffer was passed to sws_scale(). It got fixed later on in FFmpeg,
but for portability and compatibility reasons still nice to avoid
crash, especially since it's not so difficult to do.

FFmpeg ticked number is #8747
The FFmpeg Git hash with the fix: ba3e771a42c2

Differential Revision: https://developer.blender.org/D8355

===================================================================

M	source/blender/imbuf/intern/anim_movie.c

===================================================================

diff --git a/source/blender/imbuf/intern/anim_movie.c b/source/blender/imbuf/intern/anim_movie.c
index 11b30a24cde..8303f91d38b 100644
--- a/source/blender/imbuf/intern/anim_movie.c
+++ b/source/blender/imbuf/intern/anim_movie.c
@@ -1186,7 +1186,29 @@ static ImBuf *ffmpeg_fetchibuf(struct anim *anim, int position, IMB_Timecode_Typ
   }
 
   IMB_freeImBuf(anim->last_frame);
-  anim->last_frame = IMB_allocImBuf(anim->x, anim->y, 32, IB_rect);
+
+  /* Certain versions of FFmpeg have a bug in libswscale which ends up in crash
+   * when destination buffer is not properly aligned. For example, this happens
+   * in FFmpeg 4.3.1. It got fixed later on, but for compatibility reasons is
+   * still best to avoid crash.
+   *
+   * This is achieved by using own allocation call rather than relying on
+   * IMB_allocImBuf() to do so since the IMB_allocImBuf() is not guaranteed
+   * to perform aligned allocation.
+   *
+   * In theory this could give better performance, since SIMD operations on
+   * aligned data are usually faster.
+   *
+   * Note that even though sometimes vertical flip is required it does not
+   * affect on alignment of data passed to sws_scale because if the X dimension
+   * is not 32 byte aligned special intermediate buffer is allocated.
+   *
+   * The issue was reported to FFmpeg under ticket #8747 in the FFmpeg tracker
+   * and is fixed in the newer versions than 4.3.1. */
+  anim->last_frame = IMB_allocImBuf(anim->x, anim->y, 32, 0);
+  anim->last_frame->rect = MEM_mallocN_aligned((size_t)4 * anim->x * anim->y, 32, "ffmpeg ibuf");
+  anim->last_frame->mall |= IB_rect;
+
   anim->last_frame->rect_colorspace = colormanage_colorspace_get_named(anim->colorspace);
 
   ffmpeg_postprocess(anim);



More information about the Bf-blender-cvs mailing list