Repository navigation
fix(encodes): remove signed left shift UB in utf8MultiByteCount - #754
Open
pppanghu77 wants to merge 1 commit into
Open
pppanghu77 wants to merge 1 commit into
pppanghu77 wants to merge 1 commit into
Conversation
Reviewer's GuideImplementationUse an unsigned byte in the leading-one counter and cast the input at the call site to avoid shifting a negative value.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
|
TAG Bot New tag: 6.6.11 |
- Change LeftBitFunc lambda parameter from char to unsigned char so the leading-ones loop no longer left-shifts a negative value (CWE-758), which UBSan trap mode reports as SIGILL illegal-instruction - Cast the byte to unsigned char explicitly at the call site; the leading-ones count is identical for every input byte 修复(encodes): 消除 utf8MultiByteCount 中的有符号左移未定义行为 - 将 LeftBitFunc lambda 形参由 char 改为 unsigned char,使前导 1 统计循环不再对负值做左移(CWE-758),UBSan trap 模式下原报 SIGILL 非法指令 - 调用处显式转换为 unsigned char;任意输入字节的前导 1 计数结果不变 Log: 修复编码探测模块 utf8MultiByteCount 对负值有符号左移的未定义行为(CWE-758) Bug: https://pms.uniontech.com/bug-view-384159.html PMS: BUG-384159
pppanghu77
force-pushed
the
fix/384159-utf8-negshift-ub-master
branch
from
November 30, 2026 07:57
54eb9cc to
34a528a
Compare
lzwind
approved these changes
Nov 30, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pppanghu77 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Contributor
Author
|
/merge |
Contributor
|
TAG Bot New tag: 6.6.12 |
Contributor
|
TAG Bot New tag: 6.6.13 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复编码探测模块 utf8MultiByteCount 的有符号左移未定义行为(CWE-758)
WingFuzz 模糊测试(ASan+UBSan 插桩)发现:
utf8MultiByteCount内LeftBitFunclambda 形参为有符号char,输入字节 ≥ 0x80 时(如 0x80 → -128)data <<= 1对负值左移属未定义行为(C++11/14 [expr.shift]),UBSan trap 模式插入 ud2 陷阱导致进程 SIGILL(detectcode.cpp内左移语句,illegal-instruction)。普通构建下该 UB "看起来正常"(0x80 左移截断为 0,返回 1),故长期潜伏。修复方式与提单建议一致:
LeftBitFunc形参char→unsigned char,消除负值左移 UBstatic_cast<unsigned char>(*buf)本 PR 为 master(V25)分支修复,与 release/eagle 的 #753 同源同内容。
验证:
left shift of negative value -128、trap 模式 SIGILL 退出码 132;修复后无诊断、退出码 0、返回值不变fix(encodes): remove signed left shift UB in utf8MultiByteCount
Log: 修复编码探测模块 utf8MultiByteCount 对负值有符号左移的未定义行为(CWE-758)
Bug: https://pms.uniontech.com/bug-view-384159.html
PMS: BUG-384159
Summary by Sourcery
Bug Fixes: