-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opj_compress/opj_uncompress: fix integer overflow in num_images (#1395)
Includes the fix for CVE-2021-29338 Credit to @kaniini based on #1346 Fixes #1338
- Loading branch information
Showing
3 changed files
with
8 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79c7d7a
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.
So I wrote a paper on this CVE for my masters program and never got around to fully implementing a fix. The call to calloc still has the same overflow issue as the malloc call, I proposed this exact fix in the paper I wrote. The two sources below outline why calloc still needs a multiplication check before calling, source A, and example CVE's that suffer from memory allocation issues related to integer overflows in calloc functions, source B .
Source-A: https://wiki.sei.cmu.edu/confluence/display/c/MEM07-C.+Ensure+that+the+arguments+to+calloc%28%29%2C+when+multiplied%2C+do+not+wrap
Source B:
https://www.avertium.com/blog/overview-badalloc-vulnerabilities
There is an additional integer overflow in the for loop on line 1969 in ops_compress, OPJ_PATH_LENGTH is 4096, it is multiplied by number of images. This loop should be covered by a multiplication check as well.
I committed the multiplication check version for review.
-Eric