kernel: rtlil: imposed a hard limit on RTLIL::Const of 2^24 (closes #3317)

This commit is contained in:
Aki Van Ness 2022-08-24 11:31:28 -04:00
parent 9ffaae91ff
commit 2b9982101a
No known key found for this signature in database
GPG Key ID: C629E8EC06327BEE
1 changed files with 23 additions and 0 deletions

View File

@ -201,6 +201,9 @@ const pool<IdString> &RTLIL::builtin_ff_cell_types() {
RTLIL::Const::Const(const std::string &str)
{
if (str.size() * 8 > 0x1000000)
throw std::length_error("RTLIL Const width must be less than 2^24");
flags = RTLIL::CONST_FLAG_STRING;
bits.reserve(str.size() * 8);
for (int i = str.size()-1; i >= 0; i--) {
@ -214,6 +217,12 @@ RTLIL::Const::Const(const std::string &str)
RTLIL::Const::Const(int val, int width)
{
if (width < 0)
throw std::length_error("RTLIL Const width must not be negative");
if (width > 0x1000000)
throw std::length_error("RTLIL Const width must be less than 2^24");
flags = RTLIL::CONST_FLAG_NONE;
bits.reserve(width);
for (int i = 0; i < width; i++) {
@ -224,6 +233,12 @@ RTLIL::Const::Const(int val, int width)
RTLIL::Const::Const(RTLIL::State bit, int width)
{
if (width < 0)
throw std::length_error("RTLIL Const width must not be negative");
if (width > 0x1000000)
throw std::length_error("RTLIL Const width must be less than 2^24");
flags = RTLIL::CONST_FLAG_NONE;
bits.reserve(width);
for (int i = 0; i < width; i++)
@ -232,6 +247,10 @@ RTLIL::Const::Const(RTLIL::State bit, int width)
RTLIL::Const::Const(const std::vector<bool> &bits)
{
if (bits.size() > 0x1000000)
throw std::length_error("RTLIL Const width must be less than 2^24");
flags = RTLIL::CONST_FLAG_NONE;
this->bits.reserve(bits.size());
for (const auto &b : bits)
@ -296,6 +315,10 @@ std::string RTLIL::Const::as_string() const
RTLIL::Const RTLIL::Const::from_string(const std::string &str)
{
if (str.size() > 0x1000000)
throw std::length_error("RTLIL width must be less than 2^24");
Const c;
c.bits.reserve(str.size());
for (auto it = str.rbegin(); it != str.rend(); it++)