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

Initialize offset memory for PyImagingPhotoPut #4806

Merged
merged 1 commit into from Oct 14, 2020

Conversation

nqbit
Copy link
Contributor

@nqbit nqbit commented Jul 21, 2020

When using image mode "1" or "L" block.offset[3] is never initialized. In some use cases the block is passed to Tk_PhotoPutBlock (https://github.com/tcltk/tk/blob/master/generic/tkImgPhoto.c#L2752) and block.offset[3] is stored in alphaoffset which is later referenced.

This change initializes block.offset[3] to 0 when using mode "1" or "L".

@nqbit nqbit marked this pull request as ready for review July 21, 2020 07:05
@radarhere radarhere changed the title Initialize offset memory for PyImagingPhotoPut. Initialize offset memory for PyImagingPhotoPut Jul 21, 2020
@radarhere
Copy link
Member

Are you aware of a situation that shows this bug? We would be interested in adding such a scenario as a test.

@nqbit
Copy link
Contributor Author

nqbit commented Jul 23, 2020

This was caught with a memory sanitizer, see the following example:

import numpy as np
from PIL import Image
from PIL import ImageTk

example_image_array = np.full((100,100), 123, dtype=np.uint8)
example_image = Image.fromarray(example_image_array)
example_image_tk = ImageTk.PhotoImage(image=example_image)

Is there currently any support for memory sanitization in the test framework?

When using image mode "1" or "L" block.offset[3] is never initialized. In some use cases the block is passed to Tk_PhotoPutBlock (https://github.com/tcltk/tk/blob/master/generic/tkImgPhoto.c#L2752) and block.offset[3] is stored in alphaoffset which is later referenced.
@radarhere
Copy link
Member

The closest we have to memory sanitization testing is #3961.

As such, while I agree that your change makes logical sense, I'm having trouble running a sanitizer over the code, since Tkinter requires a display, and my usual approach to this problem would be display-less docker.

@hugovk hugovk merged commit 14643d5 into python-pillow:master Oct 14, 2020
@nqbit
Copy link
Contributor Author

nqbit commented Oct 14, 2020

Thank you for helping to get this merged. One option for display-less configuration is xvfb (X virtual frame-buffer). https://en.wikipedia.org/wiki/Xvfb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants