Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Heap-buffer-overflow READ in opj_jp2_apply_pclr #1441

Merged
merged 2 commits into from Aug 12, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/lib/openjp2/jp2.c
Expand Up @@ -1042,7 +1042,7 @@ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image,
OPJ_UINT32 *entries;
opj_jp2_cmap_comp_t *cmap;
OPJ_INT32 *src, *dst;
OPJ_UINT32 j, max;
OPJ_UINT32 j, max, newmax, oldmax;
OPJ_UINT16 i, nr_channels, cmp, pcol;
OPJ_INT32 k, top_k;

Expand Down Expand Up @@ -1108,7 +1108,10 @@ static OPJ_BOOL opj_jp2_apply_pclr(opj_image_t *image,
pcol = cmap[i].pcol;
src = old_comps[cmp].data;
assert(src); /* verified above */
max = new_comps[pcol].w * new_comps[pcol].h;
oldmax = old_comps[cmp].w * old_comps[cmp].h;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't the fix to be just:
max = new_comps[i].w * new_comps[i].h;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be... While I understand where and why it accesses out of bounds memory, my assumption about the fix can be wrong because I'm not so familiar with the code base. I have applied and tested your suggestion and the crash is gone.

newmax = new_comps[pcol].w * new_comps[pcol].h;

max = oldmax < newmax ? oldmax : newmax;

/* Direct use: */
if (cmap[i].mtyp == 0) {
Expand Down