Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #330: Integer overflow in gdImageScaleBilinearPalette()
The color components are supposed to be in range 0..255, so we must not cast them to `signed char`, what can be the default for `char`.
- Loading branch information
Showing
5 changed files
with
39 additions
and
4 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,2 +1,3 @@ | ||
/bug00330 | ||
/github_bug_00218 | ||
/bug_overflow_large_new_size |
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,4 +1,5 @@ | ||
LIST(APPEND TESTS_FILES | ||
bug00330 | ||
github_bug_00218 | ||
bug_overflow_large_new_size | ||
) | ||
|
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,32 @@ | ||
/** | ||
* Regression test for <https://github.com/libgd/libgd/issues/330>. | ||
* | ||
* We're testing that after scaling a palette image, the center pixel actually | ||
* has the expected color value. | ||
*/ | ||
|
||
|
||
#include "gd.h" | ||
#include "gdtest.h" | ||
|
||
|
||
int main() | ||
{ | ||
gdImagePtr src, dst; | ||
int color; | ||
|
||
src = gdImageCreate(100, 100); | ||
gdImageColorAllocate(src, 255, 255, 255); | ||
|
||
gdImageSetInterpolationMethod(src, GD_BILINEAR_FIXED); | ||
dst = gdImageScale(src, 200, 200); | ||
|
||
color = gdImageGetPixel(dst, 99, 99); | ||
gdTestAssertMsg(color == 0xffffff, | ||
"expected color ffffff, but got %x\n", color); | ||
|
||
gdImageDestroy(src); | ||
gdImageDestroy(dst); | ||
|
||
return 0; | ||
} |