Skip to content

Comments

fix(utils): reject invalid hex characters in fromHex#1818

Open
robekl wants to merge 1 commit intomeshcore-dev:devfrom
robekl:fix/utils-fromhex-validate-input
Open

fix(utils): reject invalid hex characters in fromHex#1818
robekl wants to merge 1 commit intomeshcore-dev:devfrom
robekl:fix/utils-fromhex-validate-input

Conversation

@robekl
Copy link

@robekl robekl commented Feb 24, 2026

Summary

Hardens Utils::fromHex to reject non-hex characters instead of silently converting them.

Bug

Hex conversion treated invalid characters as zero-equivalent values in decode flow, allowing malformed input to pass as valid bytes.

Trigger

Provide non-hex input to flows that decode hex strings (example pattern: "zz" in a command expecting hex payload/ID).

Impact

  • Malformed identifiers/bytes accepted as valid
  • Silent data corruption during parsing
  • Commands can succeed with invalid user input, causing incorrect state changes

Fix

Introduced strict nibble validation (hexVal returns invalid for non-hex chars) and made fromHex fail-fast on invalid characters.

Make hexVal return -1 for invalid input and validate each nibble in Utils::fromHex before decoding.

Also simplify isHexChar to rely on the same validation path, preventing invalid strings from being accepted as zero bytes.
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