[FFmpeg-devel] [PATCH v8 13/13] avfilter/graphicsub2text: Add new graphicsub2text filter (OCR)

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Wed Sep 22 05:25:46 EEST 2021


Soft Works:
> 
> 
>> -----Original Message-----
>> From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of Andreas
>> Rheinhardt
>> Sent: Wednesday, 22 September 2021 04:05
>> To: ffmpeg-devel at ffmpeg.org
>> Subject: Re: [FFmpeg-devel] [PATCH v8 13/13] avfilter/graphicsub2text: Add
>> new graphicsub2text filter (OCR)
>>
>>> +
>>> +static void uninit(AVFilterContext *ctx)
>>> +{
>>> +    SubOcrContext *s = ctx->priv;
>>> +
>>> +    TessBaseAPIEnd(s->tapi);
>>> +    TessBaseAPIDelete(s->tapi);
>>
>> Beware: uninit is also called on init failure, so it might be that
>> s->tapi is NULL or that TessBaseAPIInit4 did not succeed.
> 
> vf_ocr does it in the same way, so I assumed it to be safe.
> 

I wish it were that easy. Our own APIs are (usually) safe in the sense
that an object that has been memset to zero (as all those contexts are
initially) can be passed to the free function even when it has never
been initialized. But this is need not be true for external APIs. And
unfortunately error paths are often untested.
For a bad example, just take a look at vf_libvmaf.c: It's uninit
function locks a mutex, regardless of whether said mutex has been
initialized at all. That's UB.

> Unfortunately there's no proper API documentation for tesseract.
> 




More information about the ffmpeg-devel mailing list