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

@ -368,6 +368,7 @@ gi_callable_info_get_arg (GICallableInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_CALLABLE_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
offset = signature_offset (info);
header = (Header *)rinfo->typelib->data;
@ -401,6 +402,7 @@ gi_callable_info_load_arg (GICallableInfo *info,
g_return_if_fail (info != NULL);
g_return_if_fail (GI_IS_CALLABLE_INFO (info));
g_return_if_fail (n <= G_MAXUINT16);
offset = signature_offset (info);
header = (Header *)rinfo->typelib->data;

View File

@ -118,6 +118,7 @@ gi_enum_info_get_value (GIEnumInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_ENUM_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
header = (Header *)rinfo->typelib->data;
offset = rinfo->offset + header->enum_blob_size
@ -171,6 +172,7 @@ gi_enum_info_get_method (GIEnumInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_ENUM_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
header = (Header *)rinfo->typelib->data;
blob = (EnumBlob *)&rinfo->typelib->data[rinfo->offset];

View File

@ -89,6 +89,7 @@ gi_interface_info_get_prerequisite (GIInterfaceInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
@ -142,6 +143,7 @@ gi_interface_info_get_property (GIInterfaceInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
header = (Header *)rinfo->typelib->data;
blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
@ -199,6 +201,7 @@ gi_interface_info_get_method (GIInterfaceInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
header = (Header *)rinfo->typelib->data;
blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
@ -287,6 +290,7 @@ gi_interface_info_get_signal (GIInterfaceInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
header = (Header *)rinfo->typelib->data;
blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
@ -382,6 +386,7 @@ gi_interface_info_get_vfunc (GIInterfaceInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
header = (Header *)rinfo->typelib->data;
blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];
@ -481,6 +486,7 @@ gi_interface_info_get_constant (GIInterfaceInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_INTERFACE_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
header = (Header *)rinfo->typelib->data;
blob = (InterfaceBlob *)&rinfo->typelib->data[rinfo->offset];

View File

@ -275,6 +275,7 @@ gi_object_info_get_interface (GIObjectInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
@ -325,6 +326,7 @@ gi_object_info_get_field (GIObjectInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
offset = gi_object_info_get_field_offset(info, n);
@ -375,6 +377,7 @@ gi_object_info_get_property (GIObjectInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
header = (Header *)rinfo->typelib->data;
blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
@ -434,6 +437,7 @@ gi_object_info_get_method (GIObjectInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
header = (Header *)rinfo->typelib->data;
blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
@ -595,6 +599,7 @@ gi_object_info_get_signal (GIObjectInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
header = (Header *)rinfo->typelib->data;
blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
@ -693,6 +698,7 @@ gi_object_info_get_vfunc (GIObjectInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
header = (Header *)rinfo->typelib->data;
blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];
@ -868,6 +874,7 @@ gi_object_info_get_constant (GIObjectInfo *info,
g_return_val_if_fail (info != NULL, NULL);
g_return_val_if_fail (GI_IS_OBJECT_INFO (info), NULL);
g_return_val_if_fail (n <= G_MAXUINT16, NULL);
header = (Header *)rinfo->typelib->data;
blob = (ObjectBlob *)&rinfo->typelib->data[rinfo->offset];

View File

@ -798,6 +798,7 @@ gi_repository_get_info (GIRepository *repository,
DirEntry *entry;
g_return_val_if_fail (namespace != NULL, NULL);
g_return_val_if_fail (idx < G_MAXUINT16, NULL);
repository = get_repository (repository);

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);