Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Hex format validator allows empty and odd-length strings #8531

Closed
Tracked by #7226
ishantiw opened this issue Jun 2, 2023 · 1 comment · Fixed by #8556
Closed
Tracked by #7226

Hex format validator allows empty and odd-length strings #8531

ishantiw opened this issue Jun 2, 2023 · 1 comment · Fixed by #8556

Comments

@ishantiw
Copy link
Contributor

ishantiw commented Jun 2, 2023

Description

The lisk-validator method that validates hex-encoded data, isHexString, returns true if the provided string is empty ('') or consists of just one hex character (e.g., 'f'):

export const isHexString = (data: unknown): boolean => {
      if (typeof data !== 'string') {
         return false;
       }
  return data === '' || /^[a-f0-9]+$/i.test(data);
};

Both cases will cause a subsequent call to Buffer.from(data, 'hex') to return an empty Buffer object. This may violate the assumption that because the string passed hex format validation, it must encode usable data. Furthermore, when the number of characters is odd but greater than one (e.g., 'fff'), it results in incomplete decoding.

Which version(s) does this affect? (Environment, OS, etc...)

v6.0.0-beta.1

@shuse2
Copy link
Collaborator

shuse2 commented Jun 6, 2023

empty string should return true to represent the empty bytes

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants