Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
MNT: protect from out-of-bounds data access at the c level#14478
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
e50cd5b
9d1b200
44aa923
774f558
0f5fe5d
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
@pytest.mark.backend('TkAgg', skip_on_importerror=True) | ||
def test_blit(): | ||
from matplotlib.backends import _tkagg | ||
def evil_blit(photoimage, aggimage, offsets, bboxptr): | ||
data = np.asarray(aggimage) | ||
height, width = data.shape[:2] | ||
dataptr = (height, width, data.ctypes.data) | ||
_tkagg.blit( | ||
photoimage.tk.interpaddr(), str(photoimage), dataptr, offsets, | ||
bboxptr) | ||
fig, ax = plt.subplots() | ||
for bad_boxes in ((-1, 2, 0, 2), | ||
(2, 0, 0, 2), | ||
(1, 6, 0, 2), | ||
(0, 2, -1, 2), | ||
(0, 2, 2, 0), | ||
(0, 2, 1, 6)): | ||
with pytest.raises(ValueError): | ||
evil_blit(fig.canvas._tkphoto, | ||
np.ones((4, 4, 4)), | ||
(0, 1, 2, 3), | ||
bad_boxes) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -67,6 +67,11 @@ static PyObject *mpl_tk_blit(PyObject *self, PyObject *args) | ||||||
PyErr_SetString(PyExc_ValueError, "Failed to extract Tk_PhotoHandle"); | ||||||
goto exit; | ||||||
} | ||||||
if (0 > y1 || y1 > y2 || y2 > height || 0 > x1 || x1 > x2 || x2 > width) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Suggested change
I find it easier this way "y1 is smaller than 0 or larger than y2". MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. That is fair, but having all of the Moot now that@efiring merged it.. | ||||||
PyErr_SetString(PyExc_ValueError, "Attempting to draw out of bounds"); | ||||||
goto exit; | ||||||
} | ||||||
block.pixelPtr = data_ptr + 4 * ((height - y2) * width + x1); | ||||||
block.width = x2 - x1; | ||||||
block.height = y2 - y1; | ||||||