# HG changeset patch # User Sam Lantinga # Date 1279474006 25200 # Node ID af1d018ebbe6ff702fc0d7a8fcbab278087b8224 # Parent cd344ebc14e975623115633a66314c14f08394eb Better fix for bug 936 Check to for overruns before they happen instead of afterwards. diff -r cd344ebc14e9 -r af1d018ebbe6 src/video/SDL_stretch.c --- a/src/video/SDL_stretch.c Sun Jul 18 08:12:28 2010 -0700 +++ b/src/video/SDL_stretch.c Sun Jul 18 10:26:46 2010 -0700 @@ -80,7 +80,7 @@ int i; int pos, inc; - unsigned char *eip; + unsigned char *eip, *fence; unsigned char load, store; /* See if we need to regenerate the copy buffer */ @@ -116,14 +116,21 @@ pos = 0x10000; inc = (src_w << 16) / dst_w; eip = copy_row; + fence = copy_row + sizeof(copy_row)-2; for (i = 0; i < dst_w; ++i) { while (pos >= 0x10000L) { + if (eip == fence) { + return -1; + } if (bpp == 2) { *eip++ = PREFIX16; } *eip++ = load; pos -= 0x10000L; } + if (eip == fence) { + return -1; + } if (bpp == 2) { *eip++ = PREFIX16; } @@ -132,11 +139,6 @@ } *eip++ = RETURN; - /* Verify that we didn't overflow (too late!!!) */ - if (eip > (copy_row + sizeof(copy_row))) { - SDL_SetError("Copy buffer overflow"); - return (-1); - } #ifdef HAVE_MPROTECT /* Make the code executable but not writeable */ if (mprotect(copy_row, sizeof(copy_row), PROT_READ | PROT_EXEC) < 0) {