mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-07-30 13:53:30 +02:00
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:
@@ -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);
|
||||
|
Reference in New Issue
Block a user