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 --- 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);