Skip to content

NULL pointer dereference in stb_image.h #160

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

Closed
eldstal opened this issue Dec 14, 2021 · 3 comments
Closed

NULL pointer dereference in stb_image.h #160

eldstal opened this issue Dec 14, 2021 · 3 comments

Comments

@eldstal
Copy link

eldstal commented Dec 14, 2021

Vulnerable versions

  • saitoha/libsixel at the latest (6a5be8b) commit
  • libsixel/libsixel at the latest (bc93c8c) commit

Steps to reproduce

img2sixel stbio_1561_poc.bin

Input file (a malformed PICT-format image) is attached.

Cause

Segmentation fault in stbi__convert_format at stb_image.h:1561:

   switch (STBI__COMBO(img_n, req_comp)) {
     /* ... */
     STBI__CASE(4,3) { dest[0]=src[0],dest[1]=src[1],dest[2]=src[2]; } break;
     /* ... */
   }

The src pointer is NULL, as passed in from stbi__pic_load.

The source of the NULL pointer is the malloc at line 6120:

   result = (stbi_uc *) stbi__malloc_mad4(x, y, 4, 0);

whose output is never checked for NULL. The x and y dimensions (39168, 5888) are read
directly from the input file, and they pass the check in stbi__mad3sizes_valid which
only checks for integer overflow.

The total size of the allocated buffer is 39168 * 5888 * 4 and allocation fails.

Impact

Denial of service is the only obvious impact.

Mitigation

stb_image starting at version 2.27 (50072f66589f52f51eb5b3f56b9272ea8ec1fdac) include a check for this condition. libsixel should be brought up-to-date with this version if possible.

If not, backport the check as well as similar error checks for other malloc calls.

@eldstal
Copy link
Author

eldstal commented Dec 14, 2021

This same report was also submitted in the fork.

@eldstal
Copy link
Author

eldstal commented Dec 15, 2021

Fixed by @dankamongmen in commit f283ece of the libsixel/libsixel fork.

@eldstal eldstal closed this as completed Dec 15, 2021
@eldstal
Copy link
Author

eldstal commented Jan 25, 2022

This vulnerability has been assigned CVE-2021-45340.

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

No branches or pull requests

1 participant