From 0308e1f010cd8650840fa0ceee3b342229982420 Mon Sep 17 00:00:00 2001 From: Xiao-Yong Date: Fri, 5 Apr 2019 12:44:47 -0600 Subject: devdraw: fix cocoa metal _flushmemscreen for invalid rectangles (#240) It is possible to receive multiple screen resize events, and resizeimg would be called for different sizes, before _flushmemscreen actually gets called with rectangle sizes different from the most recent resizeimg call. The size mismatch would trigger illegal memory access inside _flushmemscreen. This commit protects _flushmemscreen by returning early if the requested rectangle is outside of the current texture rectangle. --- src/cmd/devdraw/cocoa-screen-metal.m | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/cmd/devdraw') diff --git a/src/cmd/devdraw/cocoa-screen-metal.m b/src/cmd/devdraw/cocoa-screen-metal.m index 21123f16..78110302 100644 --- a/src/cmd/devdraw/cocoa-screen-metal.m +++ b/src/cmd/devdraw/cocoa-screen-metal.m @@ -987,6 +987,10 @@ void _flushmemscreen(Rectangle r) { LOG(@"_flushmemscreen(%d,%d,%d,%d)", r.min.x, r.min.y, Dx(r), Dy(r)); + if(!rectinrect(r, Rect(0, 0, texture.width, texture.height))){ + LOG(@"Rectangle is out of bounds, return."); + return; + } @autoreleasepool{ [texture -- cgit v1.2.3