Skip to content

Commit 77f619d

Browse files
committed
fix #215 gdImageFillToBorder stack-overflow when invalid color is used
1 parent 73f4e03 commit 77f619d

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

Diff for: src/gd.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1928,11 +1928,17 @@ BGD_DECLARE(void) gdImageFillToBorder (gdImagePtr im, int x, int y, int border,
19281928
int i;
19291929
int restoreAlphaBleding;
19301930

1931-
if (border < 0) {
1931+
if (border < 0 || color < 0) {
19321932
/* Refuse to fill to a non-solid border */
19331933
return;
19341934
}
19351935

1936+
if (!im->trueColor) {
1937+
if ((color > (im->colorsTotal - 1)) || (border > (im->colorsTotal - 1))) {
1938+
return;
1939+
}
1940+
}
1941+
19361942
leftLimit = (-1);
19371943

19381944
restoreAlphaBleding = im->alphaBlendingFlag;

Diff for: tests/gdimagefilltoborder/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/bug00037
2+
/github_bug_215

Diff for: tests/gdimagefilltoborder/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
SET(TESTS_FILES
22
bug00037
3+
github_bug_215
34
)
45

56
ADD_GD_TESTS()

Diff for: tests/gdimagefilltoborder/Makemodule.am

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
if HAVE_LIBPNG
22
libgd_test_programs += \
3-
gdimagefilltoborder/bug00037
3+
gdimagefilltoborder/bug00037 \
4+
gdimagefilltoborder/github_bug_215
45
endif
56

67
EXTRA_DIST += \

0 commit comments

Comments
 (0)