Assignment of a signed value 'str' to a bigger unsigned variable 'ucs4' at /Objects/unicodeobject.c
维护者通常 1 天内回复
@divya-git03 已经在做这个了。
开始于 2026年11月5日。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
阅读 Objects/unicodeobject.c 中的 PyUnicode_4BYTE_KIND 分支,并检查 _PyUnicodeWriter_WriteLatin1String 如何处理大于 0x7F 的字节。使用四字节 Unicode 缓冲区和 0xE9 这样的 Latin-1 字节编写一个有针对性的测试,确认符号扩展行为。结果码点仍在 Unicode 范围内且相关测试通过,即为完成。
由索引模型根据 Issue 内容生成。
描述
Bug report
Potential Problem
In /Objects/unicodeobject.c in the PyUnicode_4BYTE_KIND branch https://github.com/python/cpython/blob/3.12/Objects/unicodeobject.c#L1922. A static analyzer has identified a genuine issue: *str is of type char (which is signed on x86/x64 architectures). Consequently, when Latin-1 bytes in the range 0x80–0xFF are cast to Py_UCS4, they undergo sign extension—for example, 0xE9 becomes 0xFFFFFFE9. This value exceeds MAX_UNICODE and violates the invariants of the str object. This code path can be triggered via the exported function _PyUnicodeWriter_WriteLatin1String when using a PyUnicode_4BYTE_KIND buffer (while not invoked internally by CPython itself, the issue can manifest in extensions). The fix is to introduce an intermediate cast to Py_UCS1
case PyUnicode_4BYTE_KIND: {
Py_UCS4 *start = (Py_UCS4 *)data + index;
Py_UCS4 *ucs4 = start;
for (; str < end; ++ucs4, ++str)
*ucs4 = (Py_UCS4)*str;
assert((ucs4 - start) <= PyUnicode_GET_LENGTH(unicode));
break;
}
default:
Py_UNREACHABLE();
}
}
Possible Solution
Add an intermediate cast to Py_UCS1:
*ucs4 = (Py_UCS4)(Py_UCS1)*str;
Found by Linux Verification Center (portal.linuxtesting.ru (https://portal.linuxtesting.ru/)) with SVACE.
Author D. Babushkin.
CPython versions tested on:
3.12
Operating systems tested on:
No response
- 主要语言
- Python
- 星标
- 77.9k
- 派生
- 37.1k
- 平均合并
- 17 小时 19 分钟
- 30 天内合并 PR
- 679
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/cpython 的其他 Issue
-
build OS-unsupported OS-windows type-bug
难度 2/5 1-3 小时 新手友好度 60/100
维护者通常 1 天内回复
-
What's New in 3.12 credits the unstable C API tier to PEP 697 instead of PEP 689可能已有人在做 @TheLouisMahdi 于 4 天前认领。 未关闭docs
难度 1/5 1 小时以内 新手友好度 82/100
python/cpython#161078 · 3 条评论 ·
维护者通常 1 天内回复
-
OS-windows type-bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
docs
难度 2/5 1-3 小时 新手友好度 72/100
python/cpython#161007 · 4 条评论 ·
维护者通常 1 天内回复
-
tests topic-profiling type-bug
难度 2/5 1-3 小时 新手友好度 76/100
python/cpython#160881 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
didi/helixharness#18 ·
-
request-theme
难度 1/5 1 小时以内 新手友好度 78/100
LizardByte/ThemerrDB#9883 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
NousResearch/hermes-agent#149885 ·
维护者通常 1 天内回复
-
Set cache_ok = True on GUID TypeDecorator to enable SQLAlchemy query caching可能已有人在做 @patelshivani2283-lab 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 91/100
fedora-infra/anitya#2157 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
Project-MONAI/MONAI#9258 ·
维护者通常 3 天内回复