1
0
forked from M-Labs/nac3

Compare commits

...

2 Commits

Author SHA1 Message Date
Pachigulla Ramtej
ad90a6cf9a Implement check for memory corruption 2025-04-11 15:00:29 +08:00
Pachigulla Ramtej
e858ca686f Implement check for memory corruption 2025-04-11 14:54:11 +08:00

View File

@ -249,6 +249,8 @@ impl Inferencer<'_> {
true
} else {
match &*self.unifier.get_ty_immutable(ret_ty) {
// For an object type, only allow a select few primitive types.
// (Note: you may wish to also allow strings if thats acceptable.)
TypeEnum::TObj { .. } => [
self.primitives.int32,
self.primitives.int64,
@ -259,7 +261,23 @@ impl Inferencer<'_> {
]
.iter()
.any(|allowed_ty| self.unifier.unioned(ret_ty, *allowed_ty)),
TypeEnum::TTuple { ty, .. } => ty.iter().all(|t| self.check_return_value_ty(*t)),
// For a tuple, first check that none of the elements are lists or NDArrays.
// Then, recursively ensure that each element is also a safe return type.
TypeEnum::TTuple { ty, .. } => {
for &elem_ty in ty {
if let TypeEnum::TObj { obj_id, .. } = &*self.unifier.get_ty_immutable(elem_ty) {
// Here we try to get the concrete identifier of the object.
if *obj_id == PrimDef::List.id() || *obj_id == PrimDef::NDArray.id() {
return false;
}
}
}
// Recursively check that all tuple element types are acceptable.
ty.iter().all(|t| self.check_return_value_ty(*t))
},
// Any other type is disallowed.
_ => false,
}
}