allocating the rasterizer pool out of gray_raster_reset() is safer

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2016-08-22 14:03:40 +00:00
parent 88180bd6bf
commit f184f58bc6
3 changed files with 44 additions and 42 deletions

View file

@ -1000,7 +1000,7 @@
QT_FT_Vector* point;
QT_FT_Vector* limit;
char* tags;
char* tags;
int n; /* index of contour in outline */
int first; /* index of first point in contour */
@ -1345,6 +1345,45 @@
}
/**** RASTER OBJECT CREATION: In standalone mode, we simply use *****/
/**** a static object. *****/
static int
gray_raster_new( QT_FT_Raster* araster )
{
*araster = malloc(sizeof(TRaster));
if (!*araster) {
*araster = 0;
return ErrRaster_Memory_Overflow;
}
qt_ft_memset(*araster, 0, sizeof(TRaster));
return 0;
}
static void
gray_raster_reset( QT_FT_Raster raster, char* pool_base )
{
PRaster rast = (PRaster)raster;
if ( raster && pool_base )
{
rast->worker = (PWorker)pool_base;
rast->buffer = pool_base +
( ( sizeof ( TWorker ) + sizeof ( TCell ) - 1 ) &
~( sizeof ( TCell ) - 1 ) );
rast->buffer_size = ( ( pool_base + RASTER_POOL_SIZE ) -
rast->buffer ) & ~( sizeof ( TCell ) - 1 );
rast->band_size = rast->buffer_size / ( sizeof ( TCell ) * 8 );
}
else
{
rast->buffer = NULL;
rast->buffer_size = 0;
rast->worker = NULL;
}
}
static int
gray_raster_render( QT_FT_Raster raster,
const QT_FT_Raster_Params* params )
@ -1396,45 +1435,6 @@
return gray_convert_glyph( worker );
}
/**** RASTER OBJECT CREATION: In standalone mode, we simply use *****/
/**** a static object. *****/
static int
gray_raster_new( QT_FT_Raster* araster )
{
*araster = malloc(sizeof(TRaster));
if (!*araster) {
*araster = 0;
return ErrRaster_Memory_Overflow;
}
qt_ft_memset(*araster, 0, sizeof(TRaster));
return 0;
}
static void
gray_raster_reset( QT_FT_Raster raster )
{
PRaster rast = (PRaster)raster;
if ( raster )
{
char pool_base[RASTER_POOL_SIZE];
PWorker worker = (PWorker)pool_base;
rast->worker = worker;
rast->buffer = pool_base +
( ( sizeof ( TWorker ) + sizeof ( TCell ) - 1 ) &
~( sizeof ( TCell ) - 1 ) );
rast->buffer_size = ( ( pool_base + RASTER_POOL_SIZE ) -
rast->buffer ) & ~( sizeof ( TCell ) - 1 );
rast->band_size = rast->buffer_size / ( sizeof ( TCell ) * 8 );
}
}
const QT_FT_Raster_Funcs qt_ft_grays_raster =
{
(QT_FT_Raster_New_Func) gray_raster_new,

View file

@ -3256,7 +3256,8 @@ void QRasterPaintEnginePrivate::rasterize(QT_FT_Outline *outline,
return;
}
qt_ft_grays_raster.raster_reset(*grayRaster);
char pool_base[RASTER_POOL_SIZE];
qt_ft_grays_raster.raster_reset(*grayRaster, pool_base);
QT_FT_BBox clip_box = { deviceRect.x(),
deviceRect.y(),

View file

@ -458,6 +458,7 @@ QT_FT_BEGIN_HEADER
/* <Input> */
/* raster :: A handle to the new raster object. */
/* */
/* pool_base :: The address in memory of the render pool. */
/* */
/* <Note> */
/* Rasters can ignore the render pool and rely on dynamic memory */
@ -466,7 +467,7 @@ QT_FT_BEGIN_HEADER
/* recommended for efficiency purposes. */
/* */
typedef void
(*QT_FT_Raster_ResetFunc)( QT_FT_Raster raster);
(*QT_FT_Raster_ResetFunc)( QT_FT_Raster raster, char* pool);
#define QT_FT_Raster_Reset_Func QT_FT_Raster_ResetFunc