Skip to content

Initialize offset memory for PyImagingPhotoPut - #4806

Merged
hugovk merged 1 commit into
python-pillow:masterfrom
nqbit:msan_bug
Oct 14, 2020
Merged

hugovk merged 1 commit into
python-pillow:masterfrom
nqbit:msan_bug

Conversation

@nqbit

@nqbit nqbit commented Jul 21, 2020

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

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

@nqbit

nqbit commented Jul 23, 2020 •

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

nqbit commented Oct 14, 2020

Copy link
Copy Markdown
Contributor Author

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.

3 participants