Skip to content

Commit

Permalink
Fixed bug 936
Browse files Browse the repository at this point in the history
Make sure that eip doesn't overflow the copy buffer beforehand. :)
  • Loading branch information
slouken committed Jul 18, 2010
1 parent cb523d3 commit 0401492
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/video/SDL_stretch.c
Expand Up @@ -78,7 +78,7 @@ static int generate_rowbytes(int src_w, int dst_w, int bpp)

int i;
int pos, inc;
unsigned char *eip;
unsigned char *eip, *end;
unsigned char load, store;

/* See if we need to regenerate the copy buffer */
Expand Down Expand Up @@ -115,7 +115,8 @@ static int generate_rowbytes(int src_w, int dst_w, int bpp)
pos = 0x10000;
inc = (src_w << 16) / dst_w;
eip = copy_row;
for ( i=0; i<dst_w; ++i ) {
end = copy_row+sizeof(copy_row);
for ( i=0; i<dst_w && eip < end; ++i ) {
while ( pos >= 0x10000L ) {
if ( bpp == 2 ) {
*eip++ = PREFIX16;
Expand All @@ -132,8 +133,8 @@ static int generate_rowbytes(int src_w, int dst_w, int bpp)
*eip++ = RETURN;

/* Verify that we didn't overflow (too late!!!) */
if ( eip > (copy_row+sizeof(copy_row)) ) {
SDL_SetError("Copy buffer overflow");
if ( i < dst_w ) {
SDL_SetError("Copy buffer too small");
return(-1);
}
#ifdef HAVE_MPROTECT
Expand Down

0 comments on commit 0401492

Please sign in to comment.