Skip to content

Commit

Permalink
fix(oer): isSafeLength should not accept zero
Browse files Browse the repository at this point in the history
Since isSafeLength is used to sanitize inputs for methods like readUIntBE, it must not allow a length of zero which will trigger an exception.

Allowing zero also did not match  the type definition for SafeByteLength.
  • Loading branch information
justmoon committed Sep 27, 2022
1 parent 0510ec0 commit 9ba5e8c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/oer-utils/src/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const MAX_SAFE_BYTES = 6
export type SafeByteLength = 1 | 2 | 3 | 4 | 5 | 6

export const isSafeLength = (length: number): length is SafeByteLength =>
isInteger(length) && length >= 0 && length <= MAX_SAFE_BYTES
isInteger(length) && length >= 1 && length <= MAX_SAFE_BYTES

const INTEGER_REGEX = /^-?[0-9]+$/
export function isInteger(value: unknown): boolean {
Expand Down

0 comments on commit 9ba5e8c

Please sign in to comment.