Skip to content

Commit 2edb910

Browse files
authored
fix: Potential stack-overflow in index look-up (#1273)
The `find_elementary_pointer_type` may cause a stackoverflow by recursively calling itself if a inner type of a pointer can not be found. Mainly because of the line `unwrap_or_else(|| initial_type)`.
1 parent 96df75a commit 2edb910

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/index.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,16 +1553,13 @@ impl Index {
15531553
&'idx self,
15541554
initial_type: &'idx DataTypeInformation,
15551555
) -> &'idx DataTypeInformation {
1556-
match initial_type {
1557-
DataTypeInformation::Pointer { inner_type_name, .. } => {
1558-
let inner_type = self
1559-
.find_effective_type_info(inner_type_name)
1560-
.map(|t| self.find_intrinsic_type(t))
1561-
.unwrap_or_else(|| initial_type);
1562-
self.find_elementary_pointer_type(inner_type)
1556+
if let DataTypeInformation::Pointer { inner_type_name, .. } = initial_type {
1557+
if let Some(ty) = self.find_effective_type_info(inner_type_name) {
1558+
return self.find_elementary_pointer_type(self.find_intrinsic_type(ty));
15631559
}
1564-
_ => initial_type,
15651560
}
1561+
1562+
initial_type
15661563
}
15671564

15681565
/// Creates an iterator over all instances in the index

0 commit comments

Comments
 (0)