openjp3d: Int overflow fixed (#1159)
When compressing a lot of slices (starting from 44 FullHD slices with 3 8bit components in our experiments) the rate values are high enough to cause an int overflow that leads to negative lengths and wrong results. The cast happens too late.
This commit is contained in:
parent
948332e6ed
commit
c196b23b90
|
@ -226,10 +226,10 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp,
|
||||||
if (tcp->rates[j] <= 1) {
|
if (tcp->rates[j] <= 1) {
|
||||||
tcp->rates[j] = 0;
|
tcp->rates[j] = 0;
|
||||||
} else {
|
} else {
|
||||||
float num = (float)(tile->numcomps * (tile->x1 - tile->x0) *
|
float num = (float)tile->numcomps * (tile->x1 - tile->x0) *
|
||||||
(tile->y1 - tile->y0) * (tile->z1 - tile->z0) * volume->comps[0].prec);
|
(tile->y1 - tile->y0) * (tile->z1 - tile->z0) * volume->comps[0].prec;
|
||||||
float den = (float)(8 * volume->comps[0].dx * volume->comps[0].dy *
|
float den = 8.0f * volume->comps[0].dx * volume->comps[0].dy *
|
||||||
volume->comps[0].dz);
|
volume->comps[0].dz;
|
||||||
den = tcp->rates[j] * den;
|
den = tcp->rates[j] * den;
|
||||||
tcp->rates[j] = (num + den - 1) / den;
|
tcp->rates[j] = (num + den - 1) / den;
|
||||||
}
|
}
|
||||||
|
@ -537,10 +537,10 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp,
|
||||||
if (tcp->rates[j] <= 1) {
|
if (tcp->rates[j] <= 1) {
|
||||||
tcp->rates[j] = 0;
|
tcp->rates[j] = 0;
|
||||||
} else {
|
} else {
|
||||||
float num = (float)(tile->numcomps * (tile->x1 - tile->x0) *
|
float num = (float)tile->numcomps * (tile->x1 - tile->x0) *
|
||||||
(tile->y1 - tile->y0) * (tile->z1 - tile->z0) * volume->comps[0].prec);
|
(tile->y1 - tile->y0) * (tile->z1 - tile->z0) * volume->comps[0].prec;
|
||||||
float den = (float)(8 * volume->comps[0].dx * volume->comps[0].dy *
|
float den = 8.0f * volume->comps[0].dx * volume->comps[0].dy *
|
||||||
volume->comps[0].dz);
|
volume->comps[0].dz;
|
||||||
den = tcp->rates[j] * den;
|
den = tcp->rates[j] * den;
|
||||||
tcp->rates[j] = (num + den - 1) / den;
|
tcp->rates[j] = (num + den - 1) / den;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue