From 669023914a6a797159d40f971870117d07a737ec Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 14 Oct 2023 12:05:57 -0600 Subject: [PATCH] add bounds checks for stackless iterator (#2110) --- src/machine/gc.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/machine/gc.rs b/src/machine/gc.rs index 8bb38e17..5b1ccca3 100644 --- a/src/machine/gc.rs +++ b/src/machine/gc.rs @@ -280,9 +280,11 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> { return Some(cell); } - if self.heap[self.next as usize].get_mark_bit() == self.iter_state.mark_phase() { - let tag = HeapCellValueTag::AttrVar; - return Some(HeapCellValue::build_with(tag, next)); + if self.next < self.heap.len() as u64 { + if self.heap[self.next as usize].get_mark_bit() == self.iter_state.mark_phase() { + let tag = HeapCellValueTag::AttrVar; + return Some(HeapCellValue::build_with(tag, next)); + } } } HeapCellValueTag::Var => { @@ -297,9 +299,11 @@ impl<'a, UMP: UnmarkPolicy> StacklessPreOrderHeapIter<'a, UMP> { return Some(cell); } - if self.heap[self.next as usize].get_mark_bit() == self.iter_state.mark_phase() { - let tag = HeapCellValueTag::Var; - return Some(HeapCellValue::build_with(tag, next)); + if self.next < self.heap.len() as u64 { + if self.heap[self.next as usize].get_mark_bit() == self.iter_state.mark_phase() { + let tag = HeapCellValueTag::Var; + return Some(HeapCellValue::build_with(tag, next)); + } } } HeapCellValueTag::Str => { -- 2.54.0