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 OOB reads of the TGA decompression buffer
It is possible to craft TGA files which will overflow the decompression buffer, but not the image's bitmap. Therefore we augment the check for the bitmap's overflow with a check for the buffer's overflow. This issue had been reported by Ibrahim El-Sayed to security@libgd.org. CVE-2016-6906
- Loading branch information
Showing
6 changed files
with
59 additions
and
2 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 |
|---|---|---|
|
|
@@ -3,5 +3,6 @@ | |
| /bug00247a | ||
| /bug00248 | ||
| /bug00248a | ||
| /heap_overflow | ||
| /tga_null | ||
| /tga_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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ LIST(APPEND TESTS_FILES | |
| bug00247a | ||
| bug00248 | ||
| bug00248a | ||
| heap_overflow | ||
| tga_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
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,51 @@ | ||
| /** | ||
| * Test that the crafted TGA file doesn't trigger OOB reads. | ||
| */ | ||
|
|
||
|
|
||
| #include "gd.h" | ||
| #include "gdtest.h" | ||
|
|
||
|
|
||
| static size_t read_test_file(char **buffer, char *basename); | ||
|
|
||
|
|
||
| int main() | ||
| { | ||
| gdImagePtr im; | ||
| char *buffer; | ||
| size_t size; | ||
|
|
||
| size = read_test_file(&buffer, "heap_overflow.tga"); | ||
| im = gdImageCreateFromTgaPtr(size, (void *) buffer); | ||
| gdTestAssert(im == NULL); | ||
| free(buffer); | ||
|
|
||
| return gdNumFailures(); | ||
| } | ||
|
|
||
|
|
||
| static size_t read_test_file(char **buffer, char *basename) | ||
| { | ||
| char *filename; | ||
| FILE *fp; | ||
| size_t exp_size, act_size; | ||
|
|
||
| filename = gdTestFilePath2("tga", 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.