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

UnicodeDecodeError not caught & filename giving issues not reported. #6290

Open
GadgetSteve opened this issue May 9, 2024 · 0 comments
Open
Labels

Comments

@GadgetSteve
Copy link

Describe the issue
Running a scan and found in an otherwise working file that UnicodeDecodeError was raised crashing checkov.

Examples
Eventually found which file was causing the issue, as below, and that the yaml file contained:

    # ℹCommand-line programs to run using the OS shell.
    # 📚 https://git.io/JvXDl

    # ✏️ If the Autobuild fails

Luckly all in comments!

Exception Trace
Please share the trace for the exception and all relevant output by checkov.
To maximize the understanding, please run checkov with LOG_LEVEL set to debug
as follows:

LOG_LEVEL=DEBUG checkov ...

Not available!

Desktop (please complete the following information):

  • OS: Windows 10-64
  • Checkov Version: 3.2.85
  • Python Version: 3.12.3

Additional context
Was able to identify the problem file by modifying C:\temp\test_install_checkov\Lib\site-packages\checkov\github_actions\runner.py line 67-69
From:

            if not file_content:
                with open(f, 'r') as f_obj:
                    file_content = f_obj.read()

To:

            if not file_content:
                with open(f, 'r') as f_obj:
                    try:
                        file_content = f_obj.read()
                    except UnicodeDecodeError as err:
                        print(err)
                        print("Attempting to read:", f)
                        return None

This allowed me to actually see which file was giving the issues & since the odd characters were all in comments I was able to remove them so as to complete the run.

In general it is a shame that the UnicodeDecodeError does not give the name of the file that was being read when the exception occurred but a review of the code so as to improve reporting can allow the users to address such problems. (Or maybe add errors='xmlcharrefreplace' or errors='backslashreplace' on all open operations?)

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

No branches or pull requests

1 participant