[psaux] Signedness revisions.

Unsigned indexes are easier to check.

* src/psaux/cffdecode.c (cff_decoder_parse_charstrings): Updated.
* src/psaux/psintrp.c (cf2_interpT2CharString): Ditto.
* src/psaux/t1decode.c (t1_decoder_parse_charstrings): Ditto.
* src/type1/t1load.c (read_binary_data): Ditto.
This commit is contained in:
Alexei Podtelezhnikov 2021-10-10 23:12:12 -04:00
parent 3b036820d6
commit 77bd46e959
4 changed files with 38 additions and 40 deletions

View File

@ -1871,7 +1871,7 @@
case cff_op_put:
{
FT_Fixed val = args[0];
FT_Int idx = (FT_Int)( args[1] >> 16 );
FT_UInt idx = (FT_UInt)( args[1] >> 16 );
FT_TRACE4(( " put\n" ));
@ -1880,20 +1880,20 @@
/* didn't give a hard-coded size limit of the temporary */
/* storage array; instead, an argument of the */
/* `MultipleMaster' operator set the size */
if ( idx >= 0 && idx < CFF_MAX_TRANS_ELEMENTS )
if ( idx < CFF_MAX_TRANS_ELEMENTS )
decoder->buildchar[idx] = val;
}
break;
case cff_op_get:
{
FT_Int idx = (FT_Int)( args[0] >> 16 );
FT_UInt idx = (FT_UInt)( args[0] >> 16 );
FT_Fixed val = 0;
FT_TRACE4(( " get\n" ));
if ( idx >= 0 && idx < CFF_MAX_TRANS_ELEMENTS )
if ( idx < CFF_MAX_TRANS_ELEMENTS )
val = decoder->buildchar[idx];
args[0] = val;
@ -1914,9 +1914,9 @@
/* this operator was removed from the Type2 specification */
/* in version 16-March-2000 */
{
FT_Int reg_idx = (FT_Int)args[0];
FT_Int idx = (FT_Int)args[1];
FT_Int count = (FT_Int)args[2];
FT_UInt reg_idx = (FT_UInt)args[0];
FT_UInt idx = (FT_UInt)args[1];
FT_UInt count = (FT_UInt)args[2];
FT_TRACE4(( " load\n" ));
@ -1924,11 +1924,11 @@
/* since we currently don't handle interpolation of multiple */
/* master fonts, we store a vector [1 0 0 ...] in the */
/* temporary storage array regardless of the Registry index */
if ( reg_idx >= 0 && reg_idx <= 2 &&
idx >= 0 && idx < CFF_MAX_TRANS_ELEMENTS &&
count >= 0 && count <= num_axes )
if ( reg_idx <= 2 &&
idx < CFF_MAX_TRANS_ELEMENTS &&
count <= num_axes )
{
FT_Int end, i;
FT_UInt end, i;
end = FT_MIN( idx + count, CFF_MAX_TRANS_ELEMENTS );

View File

@ -1899,18 +1899,17 @@
/* cvi( <idx> ) of BuildCharArray with */
/* WeightVector */
{
FT_Int idx;
FT_UInt idx;
PS_Blend blend = decoder->blend;
if ( arg_cnt != 1 || !blend )
goto Unexpected_OtherSubr;
idx = cf2_stack_popInt( opStack );
idx = (FT_UInt)cf2_stack_popInt( opStack );
if ( idx < 0 ||
(FT_UInt)idx + blend->num_designs >
decoder->len_buildchar )
if ( idx + blend->num_designs >
decoder->len_buildchar )
goto Unexpected_OtherSubr;
ft_memcpy( &decoder->buildchar[idx],
@ -2010,17 +2009,16 @@
/* <val> <idx> 2 24 callothersubr */
/* ==> set BuildCharArray[cvi( <idx> )] = <val> */
{
CF2_Int idx;
CF2_UInt idx;
PS_Blend blend = decoder->blend;
if ( arg_cnt != 2 || !blend )
goto Unexpected_OtherSubr;
idx = cf2_stack_popInt( opStack );
idx = (CF2_UInt)cf2_stack_popInt( opStack );
if ( idx < 0 ||
(FT_UInt)idx >= decoder->len_buildchar )
if ( idx >= decoder->len_buildchar )
goto Unexpected_OtherSubr;
decoder->buildchar[idx] =
@ -2033,17 +2031,16 @@
/* ==> push BuildCharArray[cvi( idx )] */
/* onto T1 stack */
{
CF2_Int idx;
CF2_UInt idx;
PS_Blend blend = decoder->blend;
if ( arg_cnt != 1 || !blend )
goto Unexpected_OtherSubr;
idx = cf2_stack_popInt( opStack );
idx = (CF2_UInt)cf2_stack_popInt( opStack );
if ( idx < 0 ||
(FT_UInt)idx >= decoder->len_buildchar )
if ( idx >= decoder->len_buildchar )
goto Unexpected_OtherSubr;
cf2_stack_pushFixed( opStack,
@ -2185,29 +2182,29 @@
case cf2_escPUT:
{
CF2_F16Dot16 val;
CF2_Int idx;
CF2_UInt idx;
FT_TRACE4(( " put\n" ));
idx = cf2_stack_popInt( opStack );
idx = (CF2_UInt)cf2_stack_popInt( opStack );
val = cf2_stack_popFixed( opStack );
if ( idx >= 0 && idx < CF2_STORAGE_SIZE )
if ( idx < CF2_STORAGE_SIZE )
storage[idx] = val;
}
continue; /* do not clear the stack */
case cf2_escGET:
{
CF2_Int idx;
CF2_UInt idx;
FT_TRACE4(( " get\n" ));
idx = cf2_stack_popInt( opStack );
idx = (CF2_UInt)cf2_stack_popInt( opStack );
if ( idx >= 0 && idx < CF2_STORAGE_SIZE )
if ( idx < CF2_STORAGE_SIZE )
cf2_stack_pushFixed( opStack, storage[idx] );
}
continue; /* do not clear the stack */

View File

@ -28,7 +28,8 @@
#include "psauxerr.h"
/* ensure proper sign extension */
#define Fix2Int( f ) ( (FT_Int)(FT_Short)( (f) >> 16 ) )
#define Fix2Int( f ) ( (FT_Int)(FT_Short)( (f) >> 16 ) )
#define Fix2UInt( f ) ( (FT_UInt)(FT_Short)( (f) >> 16 ) )
/**************************************************************************
*
@ -1025,16 +1026,16 @@
/* <val> <idx> 2 24 callothersubr */
/* ==> set BuildCharArray[cvi( <idx> )] = <val> */
{
FT_Int idx;
FT_UInt idx;
PS_Blend blend = decoder->blend;
if ( arg_cnt != 2 || !blend )
goto Unexpected_OtherSubr;
idx = Fix2Int( top[1] );
idx = Fix2UInt( top[1] );
if ( idx < 0 || (FT_UInt) idx >= decoder->len_buildchar )
if ( idx >= decoder->len_buildchar )
goto Unexpected_OtherSubr;
decoder->buildchar[idx] = top[0];
@ -1046,16 +1047,16 @@
/* ==> push BuildCharArray[cvi( idx )] */
/* onto T1 stack */
{
FT_Int idx;
FT_UInt idx;
PS_Blend blend = decoder->blend;
if ( arg_cnt != 1 || !blend )
goto Unexpected_OtherSubr;
idx = Fix2Int( top[0] );
idx = Fix2UInt( top[0] );
if ( idx < 0 || (FT_UInt) idx >= decoder->len_buildchar )
if ( idx >= decoder->len_buildchar )
goto Unexpected_OtherSubr;
top[0] = decoder->buildchar[idx];

View File

@ -1356,7 +1356,7 @@
if ( cur < limit && ft_isdigit( *cur ) )
{
FT_Long s = T1_ToInt( parser );
FT_ULong s = (FT_ULong)T1_ToInt( parser );
T1_Skip_PS_Token( parser ); /* `RD' or `-|' or something else */
@ -1365,10 +1365,10 @@
/* `RD' or `-|' token */
*base = parser->root.cursor + 1;
if ( s >= 0 && s < limit - *base )
if ( s < (FT_ULong)( limit - *base ) )
{
parser->root.cursor += s + 1;
*size = (FT_ULong)s;
*size = s;
return !parser->root.error;
}
}