From 9f57fea0ee9e0162816310182a21fb58a0b69e79 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 12 Jul 2015 17:53:17 -0500 Subject: [PATCH] Backport ignoring values outside lightgrid to OpenGL1 Fixes possibly of reading memory past end of lightGridData or reading wrong light grid data (wrapping around to next row). --- code/renderergl1/tr_light.c | 6 ++++++ code/renderergl2/tr_light.c | 10 ++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/code/renderergl1/tr_light.c b/code/renderergl1/tr_light.c index 0d0a5da4..80b55f5a 100644 --- a/code/renderergl1/tr_light.c +++ b/code/renderergl1/tr_light.c @@ -182,6 +182,9 @@ static void R_SetupEntityLightingGrid( trRefEntity_t *ent ) { data = gridData; for ( j = 0 ; j < 3 ; j++ ) { if ( i & (1< tr.world->lightGridBounds[j] - 1 ) { + break; // ignore values outside lightgrid + } factor *= frac[j]; data += gridStep[j]; } else { @@ -189,6 +192,9 @@ static void R_SetupEntityLightingGrid( trRefEntity_t *ent ) { } } + if ( j != 3 ) { + continue; + } if ( !(data[0]+data[1]+data[2]) ) { continue; // ignore samples in walls } diff --git a/code/renderergl2/tr_light.c b/code/renderergl2/tr_light.c index faaa8dd3..7d3ed2a5 100644 --- a/code/renderergl2/tr_light.c +++ b/code/renderergl2/tr_light.c @@ -180,18 +180,15 @@ static void R_SetupEntityLightingGrid( trRefEntity_t *ent, world_t *world ) { byte *data; int lat, lng; vec3_t normal; - qboolean ignore; #if idppc float d0, d1, d2, d3, d4, d5; #endif factor = 1.0; data = gridData; - ignore = qfalse; for ( j = 0 ; j < 3 ; j++ ) { if ( i & (1< world->lightGridBounds[j] - 1) - { - ignore = qtrue; // ignore values outside lightgrid + if ( pos[j] + 1 > world->lightGridBounds[j] - 1 ) { + break; // ignore values outside lightgrid } factor *= frac[j]; data += gridStep[j]; @@ -200,8 +197,9 @@ static void R_SetupEntityLightingGrid( trRefEntity_t *ent, world_t *world ) { } } - if ( ignore ) + if ( j != 3 ) { continue; + } if (world->hdrLightGrid) {