diff --git a/frontends/rtlil/rtlil_parser.y b/frontends/rtlil/rtlil_parser.y index 2b8d7b7ab..0f286377b 100644 --- a/frontends/rtlil/rtlil_parser.y +++ b/frontends/rtlil/rtlil_parser.y @@ -187,7 +187,11 @@ wire_stmt: wire_options: wire_options TOK_WIDTH TOK_INT { - current_wire->width = $3; + if ($3 > 0x1000000) { + rtlil_frontend_yyerror("RTLIL error: invalid wire width, must be less than 2^24"); + } else { + current_wire->width = $3; + } } | wire_options TOK_WIDTH TOK_INVALID { rtlil_frontend_yyerror("RTLIL error: invalid wire width"); diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc index 8daf2c821..0b91f8257 100644 --- a/kernel/rtlil.cc +++ b/kernel/rtlil.cc @@ -266,6 +266,9 @@ std::string& Const::get_str() { RTLIL::Const::Const(const std::string &str) { + if (str.size() * 8 > 0x1000000) + log_error("RTLIL Const width must be less than 2^24"); + flags = RTLIL::CONST_FLAG_STRING; new ((void*)&str_) std::string(str); tag = backing_tag::string; @@ -273,6 +276,12 @@ RTLIL::Const::Const(const std::string &str) RTLIL::Const::Const(long long val) // default width 32 { + if (width < 0) + log_error("RTLIL Const width must not be negative"); + + if (width > 0x1000000) + log_error("RTLIL Const width must be less than 2^24"); + flags = RTLIL::CONST_FLAG_NONE; char bytes[] = { (char)(val >> 24), (char)(val >> 16), (char)(val >> 8), (char)val @@ -311,6 +320,12 @@ RTLIL::Const::Const(long long val, int width) RTLIL::Const::Const(RTLIL::State bit, int width) { + if (width < 0) + log_error("RTLIL Const width must not be negative"); + + if (width > 0x1000000) + log_error("RTLIL Const width must be less than 2^24"); + flags = RTLIL::CONST_FLAG_NONE; new ((void*)&bits_) bitvectype(); tag = backing_tag::bits; @@ -322,6 +337,10 @@ RTLIL::Const::Const(RTLIL::State bit, int width) RTLIL::Const::Const(const std::vector &bits) { + + if (bits.size() > 0x1000000) + log_error("RTLIL Const width must be less than 2^24"); + flags = RTLIL::CONST_FLAG_NONE; new ((void*)&bits_) bitvectype(); tag = backing_tag::bits; @@ -573,6 +592,10 @@ std::string RTLIL::Const::as_string(const char* any) const RTLIL::Const RTLIL::Const::from_string(const std::string &str) { + + if (str.size() > 0x1000000) + log_error("RTLIL width must be less than 2^24"); + Const c; bitvectype& bv = c.get_bits(); bv.reserve(str.size());