girepository: Ensure indexed access on members is not overflowing

Even though we expose member access as size_t, a GI info blob can
typically just access to an a number of values that is never bigger
than uint16_t, as that's how the typelib is defined (cfr. typelib
internal header blob sizes and n_* elements).

So let's avoid this to happen by adding a check.
This commit is contained in:
Marco Trevisan (Treviño)
2024-01-16 01:40:09 +01:00
parent acabaa1568
commit 19476db825
6 changed files with 22 additions and 0 deletions

View File

@@ -109,6 +109,8 @@ gi_struct_info_get_field (GIStructInfo *info,
{
GIRealInfo *rinfo = (GIRealInfo *)info;
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
return (GIFieldInfo *) gi_info_new (GI_INFO_TYPE_FIELD, (GIBaseInfo*)info, rinfo->typelib,
gi_struct_get_field_offset (info, n));
}
@@ -193,6 +195,8 @@ gi_struct_info_get_method (GIStructInfo *info,
Header *header = (Header *)rinfo->typelib->data;
size_t offset;
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
offset = gi_struct_get_field_offset (info, blob->n_fields) + n * header->function_blob_size;
return (GIFunctionInfo *) gi_info_new (GI_INFO_TYPE_FUNCTION, (GIBaseInfo*)info,
rinfo->typelib, offset);