* 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.
apodtele-master-patch-38950
Alexei Podtelezhnikov 2 years ago
parent 0bcb664de8
commit 81a456b28f
  1. 49
      src/base/ftobjs.c

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

Loading…
Cancel
Save