Python extractor reports parse errors for files no longer in the scanned commit

未关闭
#22,579 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python
领域
devtools

调研方向

首先,针对 commit 996e624 重现 Python 提取器的诊断结果;在该 commit 中,报告的文件已被删除,然后将提取器扫描的文件集与已检出的 commit 进行比较。使用 python -m py_compile 作为语法基线。完成的标准是:已接受的文件不会产生错误的解析错误,已删除的文件不会被报告。

由索引模型根据 Issue 内容生成。

描述

question

Setup

Observed behavior

CodeQL reports parse errors about two Python files. Here's a log sample (I've replaced my actual filenames with foo.py and bar.py):

Analysis produced the following diagnostic information:
##[group]Could not process some files due to syntax errors (2 results)
  * foo.py#L0C0:0: A parse error occurred while processing `foo.py`, and as a result this file could not be analyzed. Check the syntax of the file using the `python -m py_compile` command and correct any invalid syntax.
  * bar.py#L0C0:0: A parse error occurred while processing `bar.py`, and as a result this file could not be analyzed. Check the syntax of the file using the `python -m py_compile` command and correct any invalid syntax.
##[endgroup]

What I tried

  • I ran python -m py_compile on both files. This check completed without errors on Python 3.7, 3.8, 3.9, 3.10, 3.11, and 3.12.

  • I removed an old header from the files: # -*- coding: future_fstrings -*-. This header was a leftover from a Python 2 to Python 3 migration involving https://github.com/asottile-archive/future-fstrings. The warnings stayed. (I imagine, but am not sure, that this header caused the original parsing problem. These two files were the only ones in the repo that still had it.)

  • I checked the files for invisible characters and for a byte order mark. The only non-ASCII characters were some bullet characters inside one docstring. I replaced them with ASCII hyphens. The warnings stayed.

  • I replaced the full contents of both files with a single pass statement. The warnings stayed.

  • I deleted both files. The warnings stayed. I believe these logs confirm that CodeQL scanned the commit where I deleted the files (commit 996e624 in pull request 3584):

    ##[group]Checking out the ref
    [command]/usr/bin/git checkout --progress --force refs/remotes/pull/3584/head
    Note: switching to 'refs/remotes/pull/3584/head'.
    
    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by switching back to a branch.
    
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -c with the switch command. Example:
    
      git switch -c <new-branch-name>
    
    Or undo this operation with:
    
      git switch -
    
    Turn off this advice by setting config variable advice.detachedHead to false
    
    HEAD is now at 996e624 bisect: blow away the whole python modules to see if codeql still complains [skip tests]
    ##[endgroup]
    
Expected behavior
  • CodeQL must not report parse errors for Python files that python -m py_compile accepts.
  • CodeQL must not report parse errors for files that do not exist in the scanned commit.
主要语言
CodeQL
星标
10.1k
派生
2.1k
平均合并
2 天 11 小时
30 天内合并 PR
129

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/codeql 的其他 Issue

查看 github/codeql 的全部 Issue

相似的 Issue

更多 DevTools Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。