Skip to content

fix(core): BytesUtils.twoBytesToInt 屏蔽符号位#535

Merged
SpriCoder merged 2 commits into
masterfrom
fix/bytesutils-sign-mask
May 25, 2026
Merged

fix(core): BytesUtils.twoBytesToInt 屏蔽符号位#535
SpriCoder merged 2 commits into
masterfrom
fix/bytesutils-sign-mask

Conversation

@SpriCoder
Copy link
Copy Markdown
Collaborator

问题

BytesUtils.twoBytesToInt 在合并两个字节时直接 |=,未对低字节做 & 0xFF,导致任何 >= 128 的低字节(如数值 255)被符号扩展,解码出负数。紧邻其下的 bytesToInt 已正确做了掩码。

改动

对参与拼接的字节加 & 0xFF 掩码。该方法当前无生产调用方,新增的往返(round-trip)测试用于守护此修复。

验证

新增 BytesUtilsTest(基础类型编解码、subBytes/concat、位运算往返)共 10 例通过;spotless 通过。

说明

基于 master 的独立分支,独立测试(不依赖 BenchmarkTestBase)。

SpriCoder added 2 commits May 23, 2026 10:50
twoBytesToInt OR'd each byte without & 0xFF, so any low byte >= 128
(e.g. value 255) sign-extended and decoded to a negative int; bytesToInt
just below already masks correctly. The method had no production callers,
so the new round-trip BytesUtilsTest (primitive codecs, subBytes/concat,
bit ops) guards the fix.
@SpriCoder SpriCoder merged commit babdea5 into master May 25, 2026
2 checks passed
@SpriCoder SpriCoder deleted the fix/bytesutils-sign-mask branch May 25, 2026 16:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant