jasper-software / jasper

Official Repository for the JasPer Image Coding Toolkit
http://www.ece.uvic.ca/~mdadams/jasper
Other
223 stars 101 forks source link

JP2 regression between 1.900.2 and 2.0.12 #145

Closed packadal closed 7 years ago

packadal commented 7 years ago

Hi,

I am trying to update an old libjasper to the newest release, and am facing a regression: When I try to read the image CB_TM_QQ432.jp2 (easy to find by googling its name) I used to have in the log

data = Kakadu-v3.4
type = 0xff64 (COM); len = 89;regid = 1;
type = 0xff90 (SOT); len = 10;tileno = 0; len = 3275110; partno = 0; numparts = 0
[...]

but since the update, I have:

data = Kakadu-v3.4
type = 0xff64 (COM); len = 89;regid = 1;
cannot get marker segment
error: cannot decode code stream

The code that fails loads the image in memory and then opens it with jasper look basically like this:

jas_stream_t* jasStream = jas_stream_memopen(buffer, length);
int fmt = jas_image_getfmt( jasStream );
image = jas_image_decode( jasStream, fmt, NULL );

any suggestions ? Thanks.

packadal commented 7 years ago

Hi again, I bisected and found the regression comes from the commit 7df7cf2d4e82280b2239f309d88a3037349617d3.

This commit introduces new sanity checks, namely :

if (sot->tileno > 65534 || sot->len < 12 || sot->partno > 254 ||
  sot->numparts < 1 || sot->numparts > 255) {
    return -1;
}

The offending part as far as CB_TM_QQ432.jp2 is concerned is sot->numparts < 1, as it has a value of 0.

I don't pretend to understand completely the code, but would removing this check be valid ?

mdadams commented 7 years ago

The above problem is now fixed as of commit 769cd48e3dd96c3cac060c4d707ac7090dd13ab7.

packadal commented 7 years ago

Excellent, thank you! I had done the same in my local version, happy to see I won't need to maintain a set of patches!