Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TryParse/Parse does not detect invalid string content #74

Open
lassevk opened this issue Jun 5, 2024 · 0 comments · May be fixed by #67
Open

TryParse/Parse does not detect invalid string content #74

lassevk opened this issue Jun 5, 2024 · 0 comments · May be fixed by #67

Comments

@lassevk
Copy link

lassevk commented Jun 5, 2024

According to the "canonical spec":

Technically, a 26-character Base32 encoded string can contain 130 bits of information, whereas a ULID must only contain 128 bits. Therefore, the largest valid ULID encoded in Base32 is 7ZZZZZZZZZZZZZZZZZZZZZZZZZ, which corresponds to an epoch time of 281474976710655 or 2 ^ 48 - 1.

Any attempt to decode or encode a ULID larger than this should be rejected by all implementations, to prevent overflow bugs.

However, parsing 26 Z's succeeds, even though it clamps the value to the maximum possible value.

Furthermore, parsing any string consisting of 26 characters succeeds, regardless of the characters, whereas only a subset of all possible 26-character strings are valid Ulids.

Example:

Console.WriteLine(Ulid.TryParse(",,,,,,,,,,,,,,,,,,,,,,,,,,", out Ulid u));

outputs:

True
@jesse-black jesse-black linked a pull request Oct 7, 2024 that will close this issue
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 a pull request may close this issue.

1 participant