fix(encoding/ghash): PJW64 should use 64-bit width#4728
fix(encoding/ghash): PJW64 should use 64-bit width#4728guoxing-li wants to merge 1 commit intogogf:masterfrom
Conversation
|
@guoxing-li 老哥,感谢贡献,但是CI失败了哦。 |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the PJW64 hash function in encoding/ghash/ghash_pjw.go, where the BitsInUnsignedInt variable was incorrectly set to 32 instead of 64. This caused the 64-bit variant of the PJW hash algorithm to compute the wrong shift amounts (ThreeQuarters, OneEighth) and HighBits mask, effectively running as a 32-bit-wide algorithm in a 64-bit context.
Changes:
- Corrects
BitsInUnsignedIntinPJW64from32to64, making the algorithm genuinely 64-bit.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| func PJW64(str []byte) uint64 { | ||
| var ( | ||
| BitsInUnsignedInt uint64 = 32 // 4 * 8 | ||
| BitsInUnsignedInt uint64 = 64 // 4 * 8 |
There was a problem hiding this comment.
This fix changes the hash algorithm's computation, which means PJW64 will now produce a different output for the same input compared to before. The existing unit test in ghash_z_unit_test.go (line 79) still asserts the old expected value of uint64(31150), which was computed using the incorrect 32-bit-wide parameters. The test expected value must be updated to the new correct output produced by the 64-bit algorithm, otherwise the test suite will fail.
| func PJW64(str []byte) uint64 { | ||
| var ( | ||
| BitsInUnsignedInt uint64 = 32 // 4 * 8 | ||
| BitsInUnsignedInt uint64 = 64 // 4 * 8 |
There was a problem hiding this comment.
The inline comment // 4 * 8 on the BitsInUnsignedInt line is now stale. The value was changed to 64 to correctly represent a 64-bit integer (8 bytes × 8 bits), so the comment should be updated to // 8 * 8 to remain accurate.
| BitsInUnsignedInt uint64 = 64 // 4 * 8 | |
| BitsInUnsignedInt uint64 = 64 // 8 * 8 |
Please ensure you adhere to every item in this list.
<type>[optional scope]: <description>For example,fix(os/gtime): fix time zone issue<type>is mandatory and can be one offix,feat,build,ci,docs,style,refactor,perf,test,chorefix: Used when a bug has been fixed.feat: Used when a new feature has been added.build: Used for modifications to the project build system, such as changes to dependencies, external interfaces, or upgrading Node version.ci: Used for modifications to continuous integration processes, such as changes to Travis, Jenkins workflow configurations.docs: Used for modifications to documentation, such as changes to README files, API documentation, etc.style: Used for changes to code style, such as adjustments to indentation, spaces, blank lines, etc.refactor: Used for code refactoring, such as changes to code structure, variable names, function names, without altering functionality.perf: Used for performance optimization, such as improving code performance, reducing memory usage, etc.test: Used for modifications to test cases, such as adding, deleting, or modifying test cases for code.chore: Used for modifications to non-business-related code, such as changes to build processes or tool configurations.<type>, specify the affected package name or scope in parentheses, for example,(os/gtime).Fixes #1234orUpdates #1234(the latter if this is not a complete fix) to this comment
提交前请遵守每个事项,感谢!
<类型>[可选 范围]: <描述>例如fix(os/gtime): fix time zone issue<类型>是必须的,可以是fix、feat、build、ci、docs、style、refactor、perf、test、chore中的一个<类型>后在括号中填写受影响的包名或范围,例如(os/gtime)Fixes #1234,如果不是完全修复则添加Updates #1234