Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed freeing pointer in ImageDraw.Outline.transform #5909

Merged
merged 1 commit into from Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions Tests/test_imagedraw.py
Expand Up @@ -467,6 +467,23 @@ def test_shape2():
assert_image_equal_tofile(im, "Tests/images/imagedraw_shape2.png")


def test_transform():
# Arrange
im = Image.new("RGB", (100, 100), "white")
expected = im.copy()
draw = ImageDraw.Draw(im)

# Act
s = ImageDraw.Outline()
s.line(0, 0)
s.transform((0, 0, 0, 0, 0, 0))

draw.shape(s, fill=1)

# Assert
assert_image_equal(im, expected)


def helper_pieslice(bbox, start, end):
# Arrange
im = Image.new("RGB", (W, H))
Expand Down
12 changes: 5 additions & 7 deletions src/libImaging/Draw.c
Expand Up @@ -1854,14 +1854,8 @@ ImagingOutlineTransform(ImagingOutline outline, double a[6]) {
eIn = outline->edges;
n = outline->count;

/* FIXME: ugly! */
outline->edges = NULL;
outline->count = outline->size = 0;

eOut = allocate(outline, n);
if (!eOut) {
outline->edges = eIn;
outline->count = outline->size = n;
ImagingError_MemoryError();
return -1;
}
Expand Down Expand Up @@ -1897,7 +1891,11 @@ ImagingOutlineTransform(ImagingOutline outline, double a[6]) {
eOut++;
}

free(eIn);
free(outline->edges);

/* FIXME: ugly! */
outline->edges = NULL;
outline->count = outline->size = 0;

return 0;
}
Expand Down