Skip to content

Commit e6775d1

Browse files
committed
feat: add key check for cache safety
1 parent fdb5348 commit e6775d1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

stacks-common/src/util/lru_cache.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ impl<K: Eq + std::hash::Hash + Clone, V: Copy> LruCache<K, V> {
120120
}
121121

122122
let node = self.order.get(*order_idx).ok_or(())?;
123+
// Safety check: if the key doesn't match, the cache is corrupted
124+
if node.key != *key {
125+
return Err(());
126+
}
127+
123128
Ok(Some(node.value))
124129
} else {
125130
Ok(None)

0 commit comments

Comments
 (0)