[mac] Fix handling of malformed Mac suitcase files.

This is only relevant on macOS platforms.

* builds/mac/ftmac.c (lookup_lwfn_by_fond): Correctly handle and check
  `base_lwfn`, which is a Pascal string.

  (read_lwfn): Check PFB chunk size.

Fixes issue #1481.
This commit is contained in:
Yuanx Shi
2026-11-10 11:23:08 +01:00
committed by Werner Lemberg
parent f1f3f7d722
commit 6065d6a40e
+16 -1
View File
@@ -857,7 +857,8 @@ typedef short ResourceIndex;
if ( noErr != FSRefMakePath( &par_ref, path_lwfn, path_size ) )
return FT_THROW( Invalid_Argument );
if ( ft_strlen( (char *)path_lwfn ) + 1 + base_lwfn[0] > path_size )
if ( (size_t)path_size <=
ft_strlen( (char *)path_lwfn ) + 1 + base_lwfn[0] )
return FT_THROW( Invalid_Argument );
/* now we have absolute dirname in path_lwfn */
@@ -867,6 +868,13 @@ typedef short ResourceIndex;
ft_strcat( (char *)path_lwfn, ":" );
dirname_len = ft_strlen( (char *)path_lwfn );
/* Guard: `base_lwfn` is a Pascal string (length byte + data). */
/* If the data is not NUL-terminated within its declared length, */
/* `ft_strcat` would read past the buffer. */
if ( ft_strlen( (char *)base_lwfn + 1 ) > (size_t)base_lwfn[0] )
return FT_THROW( Invalid_Argument );
ft_strcat( (char *)path_lwfn, (char *)base_lwfn + 1 );
path_lwfn[dirname_len + base_lwfn[0]] = '\0';
@@ -1060,6 +1068,13 @@ typedef short ResourceIndex;
}
}
/* Guard: the PFB chunk size must fit in the remaining buffer */
if ( post_size > total_size )
{
error = FT_ERR( Array_Too_Large );
goto Error;
}
ft_memcpy( p, *post_data + 2, post_size );
pfb_chunk_size += post_size;
p += post_size;