[FFmpeg-devel] [PATCH 1/2] libavfilter/signature_lookup: fix possible division by zero

Gerion Entrup gerion.entrup at flump.de
Sun May 26 18:08:09 EEST 2024


Am Freitag, 24. Mai 2024, 23:03:37 MESZ schrieb Michael Niedermayer:
> On Fri, May 24, 2024 at 12:33:11PM +0200, Gerion Entrup wrote:
> > Am Dienstag, 7. Mai 2024, 19:46:28 MESZ schrieb Michael Niedermayer:
> > > On Mon, May 06, 2024 at 12:30:39AM +0200, Gerion Entrup wrote:
> > > > ---
> > > >  libavfilter/signature_lookup.c | 2 +-
> > > >  1 file changed, 1 insertion(+), 1 deletion(-)
> > > > 
> > > > diff --git a/libavfilter/signature_lookup.c b/libavfilter/signature_lookup.c
> > > > index a0ca818a9b..b39a3e225b 100644
> > > > --- a/libavfilter/signature_lookup.c
> > > > +++ b/libavfilter/signature_lookup.c
> > > > @@ -128,7 +128,7 @@ static int get_jaccarddist(SignatureContext *sc, CoarseSignature *first, CoarseS
> > > >      int jaccarddist, i, composdist = 0, cwthcount = 0;
> > > >      for (i = 0; i < 5; i++) {
> > > >          if ((jaccarddist = intersection_word(first->data[i], second->data[i])) > 0) {
> > > > -            jaccarddist /= union_word(first->data[i], second->data[i]);
> > > > +            jaccarddist /= FFMAX(union_word(first->data[i], second->data[i]), 1);
> > > >          }
> > > 
> > > for which input data does this cause a division by 0 ?
> > 
> > Sorry for the late answer. I missed your mail somehow.
> > union_word counts the amount of one bits that are created when you are "or"ing
> > the course signatures. So, when the underlying videos are so different that all
> > bits of the created signatures are different, the "or"-operator will always
> > return 0 and so also its sum (I have not tested this).
> 
> the division only occurs if jaccarddist > 0
> 
> basically what iam asking is for which A and B do we have
> (A&B) != 0 && (A|B) == 0
> or am i misreading the code ?

Hmm, valid point. Then, this patch should be unnecessary.
Should I send 2/2 again without 1/2 then?

Gerion

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: This is a digitally signed message part.
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20240526/d2b9e966/attachment.sig>


More information about the ffmpeg-devel mailing list