The Python branch-creation port accepts an oversized `--number` and crashes at `int()` instead of rejecting it

未关闭 适合新手
#5,194 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@github-actions 已经在做这个了。

开始于 2026年10月30日。

  • #5200 来自 @github-actions —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
84/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
cli

调研方向

从 extensions/git/scripts/python/create_new_feature_branch.py 开始,重点查看第 107–116 行附近对 --number 的验证,以及第 532 行附近的转换。在构造分支之前,确定并强制执行支持的最大值,然后为最大值和一个超过最大值的输入添加测试。完成标准是:过大的输入会干净地以参数错误退出,而不是输出 traceback。

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

描述

bug-assess bug-fix bug-test fix-proposed severity-low tests-passing triage-can-wait

The Python branch-creation port accepts an oversized --number and crashes at int() instead of rejecting it

Project: github/spec-kit
Affected snapshot: 1c799bda6c136fcf42fb3475a922ccaac57e6c71

Summary

create_new_feature_branch.py validates --number only with the regular expression [0-9]+. A digit string longer than Python's integer-string conversion limit passes that check, but int(branch_number) later raises ValueError before any branch is created. The CLI reports an uncaught traceback instead of rejecting the value as out of domain.

Expected behavior

--number should be a bounded non-negative integer. An out-of-range value should produce the existing argument error (for example Error: --number must be a non-negative integer) and exit cleanly before branch construction.

Actual behavior

The regex accepts the 5,000-digit string. At feature_num = f"{int(branch_number):03d}", Python raises:

ValueError: Exceeds the limit (4300 digits) for integer string conversion

The command aborts with a traceback before git checkout.

Root cause

extensions/git/scripts/python/create_new_feature_branch.py:

  • lines 107-116: --number is checked only by re.fullmatch(r"[0-9]+", args.branch_number).
  • line 532: feature_num = f"{int(branch_number):03d}".

A digit string is not a bounded integer. The parser accepts values that the runtime cannot convert, and the conversion is not guarded.

Impact

  • A normal CLI invocation with a malformed but syntactically numeric --number crashes with an uncaught traceback instead of a user-facing error.
  • The feature-branch command aborts before creating or checking out the branch, leaving the caller with a partial/opaque failure.
  • Automated callers that pre-validate --number with the documented "non-negative integer" rule can still crash the tool.

Suggested fix

Bound the accepted value before conversion, for example:

if not re.fullmatch(r"[0-9]{1,9}", args.branch_number):
    _err("Error: --number must be a non-negative integer")
    raise SystemExit(1)

or keep the regex and wrap the conversion:

try:
    feature_num = f"{int(branch_number):03d}"
except ValueError:
    _err("Error: --number is outside the supported range")
    raise SystemExit(1)

Define the supported maximum explicitly and test both the maximum and a value above it.

主要语言
Python
星标
144k
派生
12.9k
平均合并
1 天 6 小时
30 天内合并 PR
194

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

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

github/spec-kit 的其他 Issue

查看 github/spec-kit 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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