Skip to content

Fix transposed copy size and buffer offset in wh_FlashUnit_ReadBytes#295

Merged
bigbrett merged 1 commit intowolfSSL:mainfrom
sameehj:fix
Mar 10, 2026
Merged

Fix transposed copy size and buffer offset in wh_FlashUnit_ReadBytes#295
bigbrett merged 1 commit intowolfSSL:mainfrom
sameehj:fix

Conversation

@sameehj
Copy link
Contributor

@sameehj sameehj commented Mar 10, 2026

The unaligned read path swapped the copy length and buffer index: this_size was set to offset_rem instead of (WHFU_BYTES_PER_UNIT - offset_rem), and the memcpy source used the inverse. This corrupted data on every unaligned read where offset_rem != WHFU_BYTES_PER_UNIT/2.

Added test cases for unaligned ReadBytes with offset_rem = 1, 2, 3, and 5, including a multi-phase read spanning leading partial, aligned middle, and trailing partial units.

The unaligned read path swapped the copy length and buffer index:
this_size was set to offset_rem instead of (WHFU_BYTES_PER_UNIT -
offset_rem), and the memcpy source used the inverse. This corrupted
data on every unaligned read where offset_rem != WHFU_BYTES_PER_UNIT/2.

Added test cases for unaligned ReadBytes with offset_rem = 1, 2, 3,
and 5, including a multi-phase read spanning leading partial, aligned
middle, and trailing partial units.

Signed-off-by: Sameeh Jubran <sameeh@wolfssl.com>
Copy link
Contributor

@bigbrett bigbrett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sameehj

@bigbrett bigbrett merged commit 2a334a3 into wolfSSL:main Mar 10, 2026
90 of 91 checks passed
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.

2 participants