prevent framebuffer overflows in V_DrawPatchGeneral() (#99)

This commit is contained in:
Fabian Greffrath 2021-01-08 15:07:02 +01:00 committed by GitHub
parent b37e54f2d6
commit afb99f6390
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -296,7 +296,7 @@ void V_DrawPatchGeneral(int x, int y, int scrn, patch_t *patch,
y -= SHORT(patch->topoffset);
x -= SHORT(patch->leftoffset);
#ifdef RANGECHECK
#ifdef RANGECHECK_NOTHANKS
if (x<0
||x+SHORT(patch->width) >SCREENWIDTH
|| y<0
@ -312,11 +312,21 @@ void V_DrawPatchGeneral(int x, int y, int scrn, patch_t *patch,
{
byte *desttop = screens[scrn]+y*SCREENWIDTH*4+x*2;
for ( ; col != colstop ; col += colstep, desttop+=2)
for ( ; col != colstop ; col += colstep, desttop+=2, x++)
{
const column_t *column =
(const column_t *)((byte *)patch + LONG(patch->columnofs[col]));
// [FG] prevent framebuffer overflows
{
// [FG] too far left
if (x < 0)
continue;
// [FG] too far right, too wide
if (x >= SCREENWIDTH)
break;
}
// step through the posts in a column
while (column->topdelta != 0xff)
{
@ -326,6 +336,20 @@ void V_DrawPatchGeneral(int x, int y, int scrn, patch_t *patch,
register byte *dest = desttop + column->topdelta*SCREENWIDTH*4;
register int count = column->length;
// [FG] prevent framebuffer overflows
{
int topy = y + column->topdelta;
// [FG] too high
while (topy < 0)
count--, source++, dest += SCREENWIDTH*4, topy++;
// [FG] too low, too tall
while (topy + count > SCREENHEIGHT)
count--;
// [FG] nothing left to draw?
if (count < 1)
break;
}
if ((count-=4)>=0)
do
{
@ -371,11 +395,21 @@ void V_DrawPatchGeneral(int x, int y, int scrn, patch_t *patch,
{
byte *desttop = screens[scrn]+y*SCREENWIDTH+x;
for ( ; col != colstop ; col += colstep, desttop++)
for ( ; col != colstop ; col += colstep, desttop++, x++)
{
const column_t *column =
(const column_t *)((byte *)patch + LONG(patch->columnofs[col]));
// [FG] prevent framebuffer overflows
{
// [FG] too far left
if (x < 0)
continue;
// [FG] too far right, too wide
if (x >= SCREENWIDTH)
break;
}
// step through the posts in a column
while (column->topdelta != 0xff)
{
@ -385,6 +419,20 @@ void V_DrawPatchGeneral(int x, int y, int scrn, patch_t *patch,
register byte *dest = desttop + column->topdelta*SCREENWIDTH;
register int count = column->length;
// [FG] prevent framebuffer overflows
{
int topy = y + column->topdelta;
// [FG] too high
while (topy < 0)
count--, source++, dest += SCREENWIDTH, topy++;
// [FG] too low, too tall
while (topy + count > SCREENHEIGHT)
count--;
// [FG] nothing left to draw?
if (count < 1)
break;
}
if ((count-=4)>=0)
do
{