FN90 / openjpeg

Automatically exported from code.google.com/p/openjpeg
0 stars 0 forks source link

Problem decoding multiple tiles with get_decoded_tile when cmap/pclr/cdef boxes are present in jp2 file #484

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Compile the attached program against r2997 and patches 254 + 447
2  Run the program with the attached 0.jp2 file.  ./jp2tile 0.jp2 

What is the expected output?
See the pgm. The first tile (upper right corner) is correct the other tiles
are wrong.

What version of the product are you using? On what operating system?
cvs r2997 + patches 254 + 447. If only r2997 also the first tile is bad

When running the program with valgrind there is an error about access of
an uninitialized variable. this might cause a problem.

==16781== Invalid read of size 4
==16781==    at 0x417CC1: opj_j2k_get_tile (j2k.c:9870)
==16781==    by 0x41F010: opj_jp2_get_tile (jp2.c:2744)
==16781==    by 0x404043: opj_get_decoded_tile (openjpeg.c:511)
==16781==    by 0x4015CF: main (jp2tile.c:274)
==16781==  Address 0x4d2c518 is 24 bytes before a block of size 34,080 alloc'd
==16781==    at 0x4A057BB: calloc (vg_replace_malloc.c:593)
==16781==    by 0x4066AD: opj_j2k_read_siz (j2k.c:2220)
==16781==    by 0x4113E3: opj_j2k_read_header_procedure (j2k.c:7288)
==16781==    by 0x4116B1: opj_j2k_exec (j2k.c:7356)
==16781==    by 0x4103B7: opj_j2k_read_header (j2k.c:6851)
==16781==    by 0x41EA0F: opj_jp2_read_header (jp2.c:2560)
==16781==    by 0x403D39: opj_read_header (openjpeg.c:391)
==16781==    by 0x40146C: main (jp2tile.c:245)
==16781==

Line 9870
 9866         for (compno=0; compno < p_image->numcomps; ++compno)
 9867         {
 9868                 OPJ_INT32 l_comp_x1, l_comp_y1;
 9869
 9870                 l_img_comp->factor = p_j2k->m_private_image->comps[compno]      .factor;
 9871
 9872                 l_img_comp->x0 = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)p_      image->x0, (OPJ_INT32)l_img_comp->dx);

Original issue reported on code.google.com by hjpries...@gmail.com on 30 Mar 2015 at 12:25

Attachments:

GoogleCodeExporter commented 9 years ago
Hi hjpriester,

Quick analysis on my end.
First off, I'd like to point out that with conformant images & no patch, the 
issue(s) is/are still present.
Images with multiple tiles, cmap/pclr and/or cdef boxes will show this 
behavior. 0.jp2 has cmap/pclr and multiple tiles (but is non conformant - this 
is why patches are needed).

When looking at your code, I can see that your passing the same opj_image_t to 
opj_get_decoded_tile => That's why you're getting a valgrind error.
Not sure how this should be handled in OpenJPEG. I guess documentation, checks 
or design is flawed.
In the mean time, to get rid of this valgrind error (& possible crash - I got 
one), you shall pass a new copy of the image you got with opj_read_header on 
each iteration.
Here's why : 
1st iteration => tile properly decode, image is updated with cmap/pclr info. It 
now has 3 components instead of 1on input.
2nd iteration => This image with 3 components is fed to opj_get_decoded_tile & 
that's not what it's expecting.

Now, with this loop "fixed" :
1st iteration => you get the correct 3 components image
next iterations => only 1 component in output image, cmap/pclr info is not 
applied anymore.

I guess this can be easily fixed by removing opj_jp2_free_pclr(color); at the 
end of opj_jp2_apply_pclr (this shouldn't cause any leak, I don't know about 
other side effects)
For cdef boxes, the fix won't be that easy because data is modified inside the 
function opj_jp2_apply_cdef. A deep copy of that info shall be all that's 
needed.

Original comment by m.darb...@gmail.com on 16 May 2015 at 11:16

GoogleCodeExporter commented 9 years ago
Image from test suite with the same behavior (doesn't require patches) :
cmap/pclr :
input/nonregression/issue104_jpxstream.jp2

I couldn't find one for cdef

Original comment by m.darb...@gmail.com on 16 May 2015 at 12:01

GoogleCodeExporter commented 9 years ago
thanks for looking at it. when I use opj_read_header to create an image copy I 
get a message end of file reached.
so I guess I have to open the file, create codec for each tile then.

I also tried opj_copy_image_header but this does not fix the valgrind error.

Original comment by hjpries...@gmail.com on 18 May 2015 at 2:51