Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #492: Potential double-free in gdImage*Ptr()
Whenever `gdImage*Ptr()` calls `gdImage*Ctx()` and the latter fails, we must not call `gdDPExtractData()`; otherwise a double-free would happen. Since `gdImage*Ctx()` are void functions, and we can't change that for BC reasons, we're introducing static helpers which are used internally. We're adding a regression test for `gdImageJpegPtr()`, but not for `gdImageGifPtr()` and `gdImageWbmpPtr()` since we don't know how to trigger failure of the respective `gdImage*Ctx()` calls. This potential security issue has been reported by Solmaz Salimi (aka. Rooney).
- Loading branch information
Showing
7 changed files
with
84 additions
and
11 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
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 |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
/jpeg_empty_file | ||
/jpeg_im2im | ||
/jpeg_null | ||
/jpeg_ptr_double_free | ||
/jpeg_read | ||
/jpeg_resolution |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ IF(JPEG_FOUND) | |
LIST(APPEND TESTS_FILES | ||
jpeg_empty_file | ||
jpeg_im2im | ||
jpeg_ptr_double_free | ||
jpeg_null | ||
) | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Test that failure to convert to JPEG returns NULL | ||
* | ||
* We are creating an image, set its width to zero, and pass this image to | ||
* `gdImageJpegPtr()` which is supposed to fail, and as such should return NULL. | ||
* | ||
* See also <https://github.com/libgd/libgd/issues/381> | ||
*/ | ||
|
||
|
||
#include "gd.h" | ||
#include "gdtest.h" | ||
|
||
|
||
int main() | ||
{ | ||
gdImagePtr src, dst; | ||
int size; | ||
|
||
src = gdImageCreateTrueColor(1, 10); | ||
gdTestAssert(src != NULL); | ||
|
||
src->sx = 0; /* this hack forces gdImageJpegPtr() to fail */ | ||
|
||
dst = gdImageJpegPtr(src, &size, 0); | ||
gdTestAssert(dst == NULL); | ||
|
||
gdImageDestroy(src); | ||
|
||
return gdNumFailures(); | ||
} |