-
Notifications
You must be signed in to change notification settings - Fork 456
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 an integer overflow issue #809
Conversation
Prevent an integer overflow issue in function opj_pi_create_decode of pi.c.
l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16)); | ||
/* prevent an integer overflow issue */ | ||
l_current_pi->include = 00; | ||
if (l_step_l && l_tcp->numlayers < UINT_MAX / l_step_l - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trylab could you update the PR by replacing UINT_MAX by (1<<15)-1, hence avoiding inclusion of limits.h ? Thks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you want to avoid limits.h? IMHO using UINT_MAX is better than using an expression, especially if it is not correct (1 << 15 is a much too low limit)?
As opc_calloc takes size_t arguments, using stdint.h and SIZE_MAX would be even better:
if (l_step_l && l_tcp->numlayers < SIZE_MAX / l_step_l - 1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi detonin and stweil, thanks for your reviewing. So which form is more preferable?
I agree that 1<<15
is too small. I'll change the code of this pull request once we come to a conclusion.
Making it more secure to call opj_calloc.
Remove header file limits.h
l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16)); | ||
/* prevent an integer overflow issue */ | ||
l_current_pi->include = 00; | ||
if (l_step_l && l_tcp->numlayers < ((OPJ_UINT32)-1) / sizeof(OPJ_INT16) / l_step_l - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SIZE_MAX
or ((size_t)-1)
would be the real limit, because obj_calloc
takes size_t
parameters. On 64 bit platforms size_t
is larger than OBJ_UINT32
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Infact using SIZE_MAX
or ((size_t)-1)
is wrong here. Please see the details at #825
Replace OPJ_UINT32 with SIZE_MAX
Thanks stweil. I'll use SIZE_MAX which was defined in opj_malloc.c.
BTW, the proof-of-concept file and report have been sent via email on 22nd Aug. |
l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16)); | ||
/* prevent an integer overflow issue */ | ||
l_current_pi->include = 00; | ||
if (l_step_l && l_tcp->numlayers < ((SIZE_MAX)-1) / sizeof(OPJ_INT16) / l_step_l - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for my late comment.
The check with sizeof(OPJ_INT16)
is unnecessary since it will be done by opj_calloc
(through a call to calloc
)
We can get rid of the check of l_step_l
against 0
since l_tcp->numlayers + 1U > 0U
and l_tcp->numlayers + 1U
can't overflow.
The check can thus become:
if (l_step_l <= ((SIZE_MAX) / (l_tcp->numlayers + 1U)))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I've already updated the code.
Simplify code
Prevent an integer overflow issue in function opj_pi_create_decode of pi.c.
Prevent an integer overflow issue in function opj_pi_create_decode of
pi.c.
Hi, I found an integer overflow issue which could lead to OOB read and OOB write. I'd like to submit the proof-of-concept file and vulnerability report privately. Please give me an email address to report this issue. Thanks.
Regards,
Ke Liu of Tencent's Xuanwu LAB