openjpeg
openjpeg copied to clipboard
jp3d: BUG in tcd_init_encode
Content of the discussion:
Hi,
Compressing with JP3D as follows
~/openjpeg/openjpeg-2.1.2/build/bin/opj_jp3d_compress -i tibia.bin -m tibia.img -t 128,128,128 -o tibia.jp3d
got segfault when trying to initialize tcd for the second tile.
This happens for any tile size I tried (32, 64, 128).
Note that with no tiles (i.e. ONE tile) works.
gdb tells me that the crash is in
#0 tcd_init_encode ()
#1 j3d_encode ()
#2 main ()
My naive! bug fix in jp3d.c:
/* initialisation before tile encoding */
if (tileno == 0) {
tcd_malloc_encode(tcd, volume, cp, j3d->curtileno);
} else {
tcd_free_encode(tcd);
tcd_malloc_encode(tcd, volume, cp, j3d->curtileno);
//this must be kaputt tcd_init_encode(tcd, volume, cp, j3d->curtileno);
}
Now it works, but I am worry about the performance.
Could somebody fix this the right way?
Hi,
Compressing with JP3D as follows
~/openjpeg/openjpeg-2.1.2/build/bin/opj_jp3d_compress -i tibia.bin -m tibia.img -t 128,128,128 -o tibia.jp3d
got segfault when trying to initialize tcd for the second tile.
This happens for any tile size I tried (32, 64, 128).
Note that with no tiles (i.e. ONE tile) works.
gdb tells me that the crash is in
#0 tcd_init_encode ()
#1 j3d_encode ()
#2 main ()
My naive! bug fix in jp3d.c:
/* initialisation before tile encoding */
if (tileno == 0) {
tcd_malloc_encode(tcd, volume, cp, j3d->curtileno);
} else {
tcd_free_encode(tcd);
tcd_malloc_encode(tcd, volume, cp, j3d->curtileno);
//this must be kaputt tcd_init_encode(tcd, volume, cp, j3d->curtileno);
}
Now it works, but I am worry about the performance.
Could somebody fix this the right way?
Second comment from there:
I start to suspect that the bug is the reallocation of tilec->resolutions inside tcd_init_encode which maybe it was thought to be reused (res_max etc).
it works if I comment out line tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(res_max * sizeof(opj_tcd_resolution_t));
If I am correct about this, then the bug other than leading to a crash, because band->precincts is NULL, because it's not in turn allocated leads to a memory leak (tilec->resolutions)
someone should fix this upstream