chore: Harden instructions and program (#535)

Also enforce sane limits in program

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2025-12-30 18:20:07 -06:00
committed by GitHub
parent 49958c2ece
commit 28891ef883
17 changed files with 670 additions and 634 deletions
+7 -2
View File
@@ -18,6 +18,7 @@ use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;
use anyhow::anyhow;
impl<'a> Compiler<'a> {
pub(super) fn emit_return(&mut self, result_reg: super::Register) {
@@ -38,8 +39,8 @@ impl<'a> Compiler<'a> {
self.program.main_entry_point = 0;
self.program.max_rule_window_size =
self.rule_num_registers.iter().cloned().max().unwrap_or(0) as usize;
self.program.dispatch_window_size = self.register_counter as usize;
self.rule_num_registers.iter().cloned().max().unwrap_or(0);
self.program.dispatch_window_size = self.register_counter;
let mut rule_infos_map = BTreeMap::new();
@@ -140,6 +141,10 @@ impl<'a> Compiler<'a> {
.map_err(CompilerError::from)?;
}
self.program
.validate_limits()
.map_err(|e| CompilerError::from(anyhow!(e)))?;
Ok(self.program)
}