* src/base/ftobjs.c (FT_Request_Metrics): Avoid division by zero.

The division-by-zero might happen in broken fonts (see #1194).
Instead of returning a huge number from FT_DivFix and failing
to scale later, we now bail immediately.
This commit is contained in:
Alexei Podtelezhnikov 2023-01-04 22:41:34 -05:00
parent 0bcb664de8
commit 81a456b28f
1 changed files with 34 additions and 19 deletions

View File

@ -3280,34 +3280,49 @@
scaled_h = FT_REQUEST_HEIGHT( req );
/* determine scales */
if ( req->height || !req->width )
{
if ( h == 0 )
{
FT_ERROR(( "FT_Request_Metrics: Divide by zero\n" ));
error = FT_ERR( Divide_By_Zero );
goto Exit;
}
metrics->y_scale = FT_DivFix( scaled_h, h );
}
if ( req->width )
{
if ( w == 0 )
{
FT_ERROR(( "FT_Request_Metrics: Divide by zero\n" ));
error = FT_ERR( Divide_By_Zero );
goto Exit;
}
metrics->x_scale = FT_DivFix( scaled_w, w );
if ( req->height )
{
metrics->y_scale = FT_DivFix( scaled_h, h );
if ( req->type == FT_SIZE_REQUEST_TYPE_CELL )
{
if ( metrics->y_scale > metrics->x_scale )
metrics->y_scale = metrics->x_scale;
else
metrics->x_scale = metrics->y_scale;
}
}
else
{
metrics->y_scale = metrics->x_scale;
scaled_h = FT_MulDiv( scaled_w, h, w );
}
}
else
{
metrics->x_scale = metrics->y_scale = FT_DivFix( scaled_h, h );
metrics->x_scale = metrics->y_scale;
scaled_w = FT_MulDiv( scaled_h, w, h );
}
if ( !req->height )
{
metrics->y_scale = metrics->x_scale;
scaled_h = FT_MulDiv( scaled_w, h, w );
}
if ( req->type == FT_SIZE_REQUEST_TYPE_CELL )
{
if ( metrics->y_scale > metrics->x_scale )
metrics->y_scale = metrics->x_scale;
else
metrics->x_scale = metrics->y_scale;
}
Calculate_Ppem:
/* calculate the ppems */
if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL )