Kaynağa Gözat

Error if DefPackage doesn't contain correct number of elements

Isaac Woods 4 yıl önce
ebeveyn
işleme
6146d0fa2d
2 değiştirilmiş dosya ile 6 ekleme ve 1 silme
  1. 2 0
      aml/src/lib.rs
  2. 4 1
      aml/src/type2.rs

+ 2 - 0
aml/src/lib.rs

@@ -619,6 +619,8 @@ pub enum AmlError {
     UnterminatedStringConstant,
     InvalidStringConstant,
     InvalidRegionSpace(u8),
+    /// Produced when a `DefPackage` contains a different number of elements to the package's length.
+    InvalidPackage,
     /// Emitted by a parser when it's clear that the stream doesn't encode the object parsed by
     /// that parser (e.g. the wrong opcode starts the stream). This is handled specially by some
     /// parsers such as `or` and `choice!`.

+ 4 - 1
aml/src/type2.rs

@@ -276,7 +276,10 @@ where
                         package_contents.push(value);
                     }
 
-                    assert_eq!(package_contents.len(), num_elements as usize);
+                    if package_contents.len() != num_elements as usize {
+                        return Err((input, context, AmlError::InvalidPackage));
+                    }
+
                     Ok((input, context, AmlValue::Package(package_contents)))
                 }
             }),