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 invalid read in gdImageCreateFromTiffPtr()
tiff_invalid_read.tiff is corrupt, and causes an invalid read in gdImageCreateFromTiffPtr(), but not in gdImageCreateFromTiff(). The culprit is dynamicGetbuf(), which doesn't check for out-of-bound reads. In this case, dynamicGetbuf() is called with a negative dp->pos, but also positive buffer overflows have to be handled, in which case 0 has to be returned (cf. commit 75e29a9). Fixing dynamicGetbuf() exhibits that the corrupt TIFF would still create the image, because the return value of TIFFReadRGBAImage() is not checked. We do that, and let createFromTiffRgba() fail if TIFFReadRGBAImage() fails. This issue had been reported by Ibrahim El-Sayed to security@libgd.org. CVE-2016-6911
- Loading branch information
Showing
9 changed files
with
94 additions
and
19 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /tiff_dpi | ||
| /tiff_im2im | ||
| /tiff_null | ||
| /tiff_invalid_read |
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(TIFF_FOUND) | ||
| LIST(APPEND TESTS_FILES | ||
| tiff_im2im | ||
| tiff_invalid_read | ||
| tiff_null | ||
| tiff_dpi | ||
| ) | ||
|
|
||
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,61 @@ | ||
| /* | ||
| We're testing that reading corrupt TIFF files doesn't cause any memory issues, | ||
| and that the operation gracefully fails (i.e. gdImageCreateFromTiffPtr() returns | ||
| NULL). | ||
| */ | ||
|
|
||
| #include "gd.h" | ||
| #include "gdtest.h" | ||
|
|
||
|
|
||
| static void check_file(char *basename); | ||
| static size_t read_test_file(char **buffer, char *basename); | ||
|
|
||
|
|
||
| int main() | ||
| { | ||
| check_file("tiff_invalid_read_1.tiff"); | ||
| check_file("tiff_invalid_read_2.tiff"); | ||
| check_file("tiff_invalid_read_3.tiff"); | ||
|
|
||
| return gdNumFailures(); | ||
| } | ||
|
|
||
|
|
||
| static void check_file(char *basename) | ||
| { | ||
| gdImagePtr im; | ||
| char *buffer; | ||
| size_t size; | ||
|
|
||
| size = read_test_file(&buffer, basename); | ||
| im = gdImageCreateFromTiffPtr(size, (void *) buffer); | ||
| gdTestAssert(im == NULL); | ||
| free(buffer); | ||
| } | ||
|
|
||
|
|
||
| static size_t read_test_file(char **buffer, char *basename) | ||
| { | ||
| char *filename; | ||
| FILE *fp; | ||
| size_t exp_size, act_size; | ||
|
|
||
| filename = gdTestFilePath2("tiff", basename); | ||
| fp = fopen(filename, "rb"); | ||
| gdTestAssert(fp != NULL); | ||
|
|
||
| fseek(fp, 0, SEEK_END); | ||
| exp_size = ftell(fp); | ||
| fseek(fp, 0, SEEK_SET); | ||
|
|
||
| *buffer = malloc(exp_size); | ||
| gdTestAssert(*buffer != NULL); | ||
| act_size = fread(*buffer, sizeof(**buffer), exp_size, fp); | ||
| gdTestAssert(act_size == exp_size); | ||
|
|
||
| fclose(fp); | ||
| free(filename); | ||
|
|
||
| return act_size; | ||
| } |
Binary file not shown.
Binary file not shown.
Binary file not shown.