Skip to content

Conversation

@MrApplejuice
Copy link
Contributor

Dear library maintainers. I found this bug while working on my work-project, but I do not have any knowledge of how jpeg2000 compression works internally, so this is a "contextual fix". Here my observations and analysis:

Symptoms

I am working with images stored on AWS HealthImaging. AWS is transcoding medical data to jpeg2000 compressed images. AWS also computes CRC32 checksums on the decompressed image data. While working on a data-loader, I noticed that CRC32 sums randomly did not match.

I turned to valgrind and analyzed my loader and traced the issue to the line

if (is_signed[comp_num] && nlt_type3[comp_num] == type3)

for which valgrind reported that this "conditional jump depends on unitialized data".

Analysis

By adding some more if-statements, I found out that the uninitialized data meant was nlt_type3[comp_num]. This seems to get initialized in this code section:

num_bits[i] = szp->get_bit_depth(i);
is_signed[i] = szp->is_signed(i);
bool result = nlp->get_nonlinear_transform(i, bd, is, nlt_type3[i]);
if (result == true && (bd != num_bits[i] || is != is_signed[i]))
OJPH_ERROR(0x000300A1, "Mismatch between Ssiz (bit_depth = %d, "
"is_signed = %s) from SIZ marker segment, and BDnlt "
"(bit_depth = %d, is_signed = %s) from NLT marker segment, "
"for component %d", i, num_bits[i],
is_signed[i] ? "True" : "False", bd, is ? "True" : "False");
cur_line[i] = 0;
reversible[i] = codestream->get_coc(i)->is_reversible();

From what I could derive, jpeg2000 images can use the "non linear transform" optionally, but if it is not used, nlp->get_nonlinear_transform(i, bd, is, nlt_type3[i]) returns false, and nlt_type3[i] is never set. I quickly checked the param_nlt::nonlinearity type and saw that it seems to define the value OJPH_NLT_NO_NLT which seems to match this case.

Proposed solution

Set nlt_type3[i] = param_nlt::nonlinearity::OJPH_NLT_NO_NLT; when nonlinear-transform is disabled.

I have no idea if this is "correct" but it seems to fix the issue. With the fix, I now can reliably decode images from AWS HealthImaging with no hickups and valgrind is also happy.

@MrApplejuice MrApplejuice changed the title nlt_type3[i] not initialized when get_nonlinear_transform == false nlt_type3[i] not initialized when get_nonlinear_transform() == false Oct 7, 2025
@aous72
Copy link
Owner

aous72 commented Oct 8, 2025

Hi Paul,

Thank you for this extensive and very clear bug report, and for PR.

I totally agree.

Kind regards,
Aous.

@aous72 aous72 merged commit d34ecfe into aous72:master Oct 8, 2025
2 checks passed
@MrApplejuice
Copy link
Contributor Author

MrApplejuice commented Oct 8, 2025

Thank you for this extensive and very clear bug report, and for PR.

Really no problem! Thanks to you for maintaining this library and already making a hotfix release for the fix - that is very handy for me!

@aous72
Copy link
Owner

aous72 commented Oct 8, 2025

Thank you.
Just to let you know that I forgot to update the internal version when I release version 0.24.2: see #221. This has been corrected now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants