Skip to content

Commit

Permalink
[VCQ-169] Fix signed integer overflow UB leading to negative PSNR
Browse files Browse the repository at this point in the history
  • Loading branch information
nilfm99 committed Aug 31, 2023
1 parent 1463603 commit 8a9a241
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions libvmaf/src/feature/integer_psnr.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <float.h>
#include <math.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>

#include "feature_collector.h"
Expand Down Expand Up @@ -172,8 +173,8 @@ static int psnr_hbd(VmafPicture *ref_pic, VmafPicture *dist_pic,
uint64_t sse = 0;
for (unsigned i = 0; i < ref_pic->h[p]; i++) {
for (unsigned j = 0; j < ref_pic->w[p]; j++) {
const int32_t e = ref[j] - dis[j];
sse += (uint32_t)(e * e);
const uint32_t e = abs(ref[j] - dis[j]);
sse += e * e;
}
ref += ref_pic->stride[p] / 2;
dis += dist_pic->stride[p] / 2;
Expand Down

0 comments on commit 8a9a241

Please sign in to comment.