File: 06_libav-log-callback-mutext.patch

package info (click to toggle)
ffdiaporama 2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 47,940 kB
  • sloc: cpp: 44,188; xml: 267; sh: 98; ansic: 53; makefile: 11
file content (35 lines) | stat: -rw-r--r-- 1,483 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Description: Make LibAvLogCallback thread safe
 FFmpeg requires the av_log callback to be threadsafe, but was not because it
 used the global "Previous" variable.
 .
 Fix by adding a QMutex and QMutexLocker to the function. Also use vsnprintf
 here to avoid any chance of a buffer overflow.
Author: James Cowgill <jcowgill@debian.org>
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/src/ffDiaporama/engine/cDeviceModelDef.cpp
+++ b/src/ffDiaporama/engine/cDeviceModelDef.cpp
@@ -430,6 +430,7 @@ QString AllowMusicExtensions="wav#aac#ad
 
 //====================================================================================================================
 QString Previous;
+QMutex  LibAvLogMutex;
 int     LastLibAvMessageLevel=0;
 
 void LibAVLogCallback(void * /*ptr*/, int level, const char *fmt, va_list vargs) {
@@ -439,12 +440,14 @@ void LibAVLogCallback(void * /*ptr*/, in
 
     char    Buf[16384*10];
     int     MessageLevel=0;
-    vsprintf(Buf,fmt,vargs);
+    vsnprintf(Buf,sizeof(Buf),fmt,vargs);
     while ((strlen(Buf)>0)&&(Buf[strlen(Buf)-1]==32)) Buf[strlen(Buf)-1]=0;
     if (strlen(Buf)>0) {
         char    End=Buf[strlen(Buf)-1];
         QString DisplayMsg;
 
+        QMutexLocker locker(&LibAvLogMutex);
+
         if ((End==10)||(End==13)) {
             while ((strlen(Buf)>0)&&((Buf[strlen(Buf)-1]==10)||(Buf[strlen(Buf)-1]==13))) Buf[strlen(Buf)-1]=0;
             DisplayMsg=QString("LIBAV: ")+Previous+QString(Buf);