Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix double-free in gdImageWebPtr()
The issue is that gdImageWebpCtx() (which is called by gdImageWebpPtr() and the other WebP output functions to do the real work) does not return whether it succeeded or failed, so this is not checked in gdImageWebpPtr() and the function wrongly assumes everything is okay, which is not, in this case, because there is a size limitation for WebP, namely that the width and height must by less than 16383. We can't change the signature of gdImageWebpCtx() for API compatibility reasons, so we introduce the static helper _gdImageWebpCtx() which returns success respective failure, so gdImageWebpPtr() and gdImageWebpPtrEx() can check the return value. We leave it solely to libwebp for now to report warnings regarding the failing write. This issue had been reported by Ibrahim El-Sayed to security@libgd.org. CVE-2016-6912
- Loading branch information
Showing
6 changed files
with
81 additions
and
30 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| /bug00111 | ||
| /bug_double_free |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| IF(WEBP_FOUND) | ||
| LIST(APPEND TESTS_FILES | ||
| bug00111 | ||
| bug_double_free | ||
| ) | ||
| ENDIF(WEBP_FOUND) | ||
|
|
||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| if HAVE_LIBWEBP | ||
| libgd_test_programs += \ | ||
| webp/bug00111 | ||
| webp/bug00111 \ | ||
| webp/bug_double_free | ||
| endif | ||
|
|
||
| EXTRA_DIST += \ | ||
| webp/CMakeLists.txt | ||
| webp/CMakeLists.txt \ | ||
| webp/bug_double_free.jpg |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * Test that a too large image doesn't trigger an double-free when written | ||
| * to memory. | ||
| */ | ||
|
|
||
|
|
||
| #include "gd.h" | ||
| #include "gdtest.h" | ||
|
|
||
|
|
||
| int main() | ||
| { | ||
| gdImagePtr im1, im2; | ||
| FILE *fp; | ||
| int size; | ||
|
|
||
| fp = gdTestFileOpen2("webp", "bug_double_free.jpg"); | ||
| gdTestAssert(fp != NULL); | ||
| im1 = gdImageCreateFromJpeg(fp); | ||
| gdTestAssert(im1 != NULL); | ||
| fclose(fp); | ||
|
|
||
| im2 = gdImageWebpPtr(im1, &size); | ||
| gdTestAssert(im2 == NULL); | ||
|
|
||
| gdImageDestroy(im1); | ||
|
|
||
| return gdNumFailures(); | ||
| } |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.