[truetype/GX] Use more robust conditions.

* src/truetype/ttgxvar.c (ft_var_readpacked{points,deltas}): Rewrite
conditions to avoid undefined behavior.
This commit is contained in:
Alexei Podtelezhnikov 2024-08-01 19:14:44 -04:00
parent 5e116bb0dc
commit 7c75b8a7bd

View File

@ -187,7 +187,7 @@
if ( runcnt & GX_PT_POINTS_ARE_WORDS )
{
if ( p + 2 * cnt > stream->limit )
if ( 2 * cnt > (FT_UInt)( stream->limit - p ) )
goto Fail;
for ( j = 0; j < cnt; j++ )
@ -198,7 +198,7 @@
}
else
{
if ( p + cnt > stream->limit )
if ( cnt > (FT_UInt)( stream->limit - p ) )
goto Fail;
for ( j = 0; j < cnt; j++ )
@ -274,9 +274,7 @@
while ( i < delta_cnt )
{
if ( p >= stream->limit )
{
goto Fail;
}
runcnt = FT_NEXT_BYTE( p );
cnt = runcnt & GX_DT_DELTA_RUN_COUNT_MASK;
@ -293,7 +291,7 @@
}
else if ( runcnt & GX_DT_DELTAS_ARE_WORDS )
{
if ( p + 2 * cnt > stream->limit )
if ( 2 * cnt > (FT_UInt)( stream->limit - p ) )
goto Fail;
for ( j = 0; j < cnt; j++ )
@ -301,7 +299,7 @@
}
else
{
if ( p + cnt > stream->limit )
if ( cnt > (FT_UInt)( stream->limit - p ) )
goto Fail;
for ( j = 0; j < cnt; j++ )