From 0eb8087744f5c35124dda4f80ac81be6985bfb32 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Fri, 4 Dec 2026 11:52:27 +0100 Subject: [PATCH] fix: pass Checkov arguments over stdin instead of the command line The E2BIG fallback from #64 scanned the whole directory, which walks every file in the repository (excluded paths, other languages, secrets on all of them) and is likely to time out on the large repositories that hit it. Start a small launcher that reads the arguments as JSON on stdin and calls Checkov in-process, so the requested file list never reaches execve and Checkov scans exactly the files the worker sent, however many there are. --- src/checkov_launcher.py | 11 +++++++++++ src/codacy_checkov.py | 15 +++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 src/checkov_launcher.py diff --git a/src/checkov_launcher.py b/src/checkov_launcher.py new file mode 100644 index 0000000..e9154a4 --- /dev/null +++ b/src/checkov_launcher.py @@ -0,0 +1,11 @@ +import json +import sys +import warnings + + +if __name__ == '__main__': + sys.argv = json.load(sys.stdin) + from checkov.main import Checkov + with warnings.catch_warnings(): + warnings.simplefilter("ignore", category=SyntaxWarning) + sys.exit(Checkov(sys.argv[1:]).run()) diff --git a/src/codacy_checkov.py b/src/codacy_checkov.py index 3334f63..17d8964 100644 --- a/src/codacy_checkov.py +++ b/src/codacy_checkov.py @@ -1,4 +1,3 @@ -import errno import os import re import sys @@ -11,6 +10,8 @@ import traceback +CHECKOV_LAUNCHER = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'checkov_launcher.py') + checkovProcess = None @@ -183,15 +184,9 @@ def runCheckov(config, srcDir): command = command + ['--framework', ','.join(frameworks)] global checkovProcess - try: - checkovProcess = Popen(command + file_opts, stdout=PIPE, cwd=srcDir, env=processEnv) - except OSError as e: - if e.errno != errno.E2BIG or not config.files: - raise - print(f"{len(config.files)} files do not fit in the command line, scanning the whole directory", file=sys.stderr) - checkovProcess = Popen(command + ['-d', '.'], stdout=PIPE, cwd=srcDir, env=processEnv) - - stdout = checkovProcess.communicate()[0] + checkovProcess = Popen([sys.executable, CHECKOV_LAUNCHER], stdin=PIPE, stdout=PIPE, cwd=srcDir, env=processEnv) + + stdout = checkovProcess.communicate(json.dumps(command + file_opts).encode('utf-8'))[0] if len(stdout) > 0: return json.loads(stdout.decode('utf-8'))