Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes potential request-length truncation by widening intermediate length computations and validating bounds before casting to uint16_t, reducing the risk of wrapped lengths in several crypto client request builders.
Changes:
- Switched intermediate request length calculations from
uint16_ttouint32_tand deferred casting until after bounds checks. - Added bounds checks in
_HkdfMakeKeyand updated length validation in ML-DSA sign/verify paths. - Added a new
bug-fix.txtfile documenting the bug and a recommended safe computation pattern.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/wh_client_crypto.c | Uses uint32_t intermediates for request sizes and checks bounds before casting to uint16_t. |
| bug-fix.txt | Adds documentation describing the truncation bug and how to address similar issues. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
… functions by using uint32_t for intermediate length computation before bounds check
dgarske
approved these changes
Mar 19, 2026
padelsbach
approved these changes
Mar 19, 2026
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.
… functions by using uint32_t for intermediate length computation before bounds check
This pull request addresses a medium-severity bug involving potential integer truncation when calculating request lengths in several cryptographic functions. The main fix is to use a wider integer type (
uint32_t) for intermediate length computations, ensuring that values are properly validated before being cast touint16_t. This prevents silent wrapping and potential security issues when handling large data sizes.Bug documentation and guidance:
bug-fix.txt, documenting the bug, its impact, and recommended steps for confirming and fixing similar issues in the future. The file specifically describes the integer truncation bug inwh_Client_MlDsaSignandwh_Client_MlDsaVerifyand provides a pattern for safe length computation.Length computation and validation fixes:
wh_Client_Ed25519Sign,wh_Client_Ed25519Verify,wh_Client_MlDsaSign,wh_Client_MlDsaVerify, and_HkdfMakeKeyfunctions insrc/wh_client_crypto.cto:uint32_tfor all intermediate calculations.uint32_tvalue againstWOLFHSM_CFG_COMM_DATA_LENbefore casting touint16_t.uint16_t req_lenafter passing the bounds check, following the recommended safe pattern. [1] [2] [3] [4] [5] [6] [7] [8]