mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-08 13:22:53 +02:00
avcodec/j2kenc: Merge dwt_norm into lambda
This moves computations out of a loop
This may help with UB in vsynth*-jpeg2000-yuva444p16
Fixes: signed integer overflow: 31665934879948800 * 9998 cannot be represented in type 'long'
Fixes: 69024/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_JPEG2000_fuzzer-5949662967169024
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit a84fbd7471
)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
parent
d02a49ba01
commit
8d294ee692
@ -1348,7 +1348,7 @@ static void makelayers(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getcut(Jpeg2000Cblk *cblk, uint64_t lambda, int dwt_norm)
|
static int getcut(Jpeg2000Cblk *cblk, uint64_t lambda)
|
||||||
{
|
{
|
||||||
int passno, res = 0;
|
int passno, res = 0;
|
||||||
for (passno = 0; passno < cblk->npasses; passno++){
|
for (passno = 0; passno < cblk->npasses; passno++){
|
||||||
@ -1360,7 +1360,7 @@ static int getcut(Jpeg2000Cblk *cblk, uint64_t lambda, int dwt_norm)
|
|||||||
dd = cblk->passes[passno].disto
|
dd = cblk->passes[passno].disto
|
||||||
- (res ? cblk->passes[res-1].disto : 0);
|
- (res ? cblk->passes[res-1].disto : 0);
|
||||||
|
|
||||||
if (((dd * dwt_norm) >> WMSEDEC_SHIFT) * dwt_norm >= dr * lambda)
|
if (dd >= dr * lambda)
|
||||||
res = passno+1;
|
res = passno+1;
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
@ -1383,11 +1383,12 @@ static void truncpasses(Jpeg2000EncoderContext *s, Jpeg2000Tile *tile)
|
|||||||
Jpeg2000Band *band = reslevel->band + bandno;
|
Jpeg2000Band *band = reslevel->band + bandno;
|
||||||
Jpeg2000Prec *prec = band->prec + precno;
|
Jpeg2000Prec *prec = band->prec + precno;
|
||||||
|
|
||||||
|
int64_t dwt_norm = dwt_norms[codsty->transform == FF_DWT53][bandpos][lev] * (int64_t)band->i_stepsize >> 15;
|
||||||
|
int64_t lambda_prime = av_rescale(s->lambda, 1 << WMSEDEC_SHIFT, dwt_norm * dwt_norm);
|
||||||
for (cblkno = 0; cblkno < prec->nb_codeblocks_height * prec->nb_codeblocks_width; cblkno++){
|
for (cblkno = 0; cblkno < prec->nb_codeblocks_height * prec->nb_codeblocks_width; cblkno++){
|
||||||
Jpeg2000Cblk *cblk = prec->cblk + cblkno;
|
Jpeg2000Cblk *cblk = prec->cblk + cblkno;
|
||||||
|
|
||||||
cblk->ninclpasses = getcut(cblk, s->lambda,
|
cblk->ninclpasses = getcut(cblk, lambda_prime);
|
||||||
(int64_t)dwt_norms[codsty->transform == FF_DWT53][bandpos][lev] * (int64_t)band->i_stepsize >> 15);
|
|
||||||
cblk->layers[0].data_start = cblk->data;
|
cblk->layers[0].data_start = cblk->data;
|
||||||
cblk->layers[0].cum_passes = cblk->ninclpasses;
|
cblk->layers[0].cum_passes = cblk->ninclpasses;
|
||||||
cblk->layers[0].npasses = cblk->ninclpasses;
|
cblk->layers[0].npasses = cblk->ninclpasses;
|
||||||
|
Loading…
Reference in New Issue
Block a user