Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] RuntimeError: Internal error #243

Closed
1 task done
Furetur opened this issue Dec 24, 2024 · 1 comment
Closed
1 task done

[BUG] RuntimeError: Internal error #243

Furetur opened this issue Dec 24, 2024 · 1 comment

Comments

@Furetur
Copy link

Furetur commented Dec 24, 2024

Describe the bug
Got this error while fuzzing with Hypothesis

Input file:

A A@

Stacktrace

tmp/41PJSO2KRV.rdl:1:4: error: mismatched input '<EOF>' expecting {'{', '(', ''', 'boolean', 'bit', 'longint', 'true', 'false', 'na', 'rw', 'wr', 'r', 'w', 'rw1', 'w1', 'rclr', 'rset', 'ruser', 'woset', 'woclr', 'wot', 'wzs', 'wzc', 'wzt', 'wclr', 'wset', 'wuser', 'compact', 'regalign', 'fullalign', 'hw', 'sw', INT, HEX_INT, VLOG_INT, STRING, '+', '-', '!', '~', '~&', '&', '|', '~|', '^', XNOR, ID}
A A@
   ^
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".../rdl/check_rdl_result.py", line 7, in main
    compile_one_file(file)
  File ".../rdl/check.py", line 22, in compile_one_file
    rdlc.compile_file(str(file))
  File ".../python3.11/site-packages/systemrdl/compiler.py", line 272, in compile_file
    parsed_tree = sa_systemrdl.parse(
                  ^^^^^^^^^^^^^^^^^^^
  File ".../python3.11/site-packages/systemrdl/parser/sa_systemrdl.py", line 81, in parse
    return _cpp_parse(stream, entry_rule_name, sa_err_listener)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../python3.11/site-packages/systemrdl/parser/sa_systemrdl.py", line 104, in _cpp_parse
    return sa_systemrdl_cpp_parser.do_parse(SystemRDLParser, stream, entry_rule_name, sa_err_listener)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Internal error

Additional context

If you are interested, this is the fuzzing code that found the bug

import random
import string
from pathlib import Path


from systemrdl import RDLCompiler, RDLCompileError
from hypothesis import given
import hypothesis.strategies as st

def write_file(text: str) -> Path:
    N = 10
    postfix = "".join(random.choices(string.ascii_uppercase + string.digits, k=N))
    path = Path(f"tmp/{postfix}.rdl")
    path.write_text(text)
    return path


def compile_one_file(file: Path):
    rdlc = RDLCompiler()
    try:
        rdlc.compile_file(str(file))
        rdlc.elaborate()
    except RDLCompileError as e:
        print(f"Compilation error: {e}")


def check_compile(text: str):
    Path("tmp").mkdir(exist_ok=True)
    file = write_file(text)
    compile_one_file(file)
    file.unlink() # The file will not be deleted if the previous line raises Exception

@given(st.text())
def test_rdl_compiler_with_text(text: str):
    check_compile(text)
@amykyta3
Copy link
Member

Thanks.
Fix will be published in next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants