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

fix: bigint coerce crash #3822

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

fix: bigint coerce crash #3822

wants to merge 3 commits into from

Conversation

kodemon
Copy link

@kodemon kodemon commented Oct 28, 2024

Discovered when parse is executed through isOptional check on ZodBigInt which adds a undefined safeParse execution to look for errors, it crashes when attempting to add undefined to BigInt as its an invalid value.

One fix here is to just try catch the instantiation and cast the coerced value to undefined if it throws and error. This way all parser checks will fail on invalid values but not crash on internal checks which provides undefined as the input value.

Perhaps another approach could be to just catch and ignore the error and let the input data checks to subsequently verify that the input value is valid. 🤔

closes #3821

Copy link

netlify bot commented Oct 28, 2024

Deploy Preview for guileless-rolypoly-866f8a ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 644af27
🔍 Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/674351829b7e130008299459
😎 Deploy Preview https://deploy-preview-3822--guileless-rolypoly-866f8a.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

try {
input.data = BigInt(input.data);
} catch {
input.data = undefined;

Choose a reason for hiding this comment

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

Maybe here should return INVALID instate of undefined

Copy link
Author

Choose a reason for hiding this comment

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

That works and looks more correct 👍🏻

src/types.ts Outdated
try {
input.data = BigInt(input.data);
} catch {
input.data = undefined;

Choose a reason for hiding this comment

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

Maybe here should return INVALID instate of undefined

Copy link
Author

Choose a reason for hiding this comment

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

That works and looks more correct 👍🏻

@kodemon kodemon marked this pull request as ready for review November 24, 2024 16:18
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.

Bigint with coerce throws exception in safeParse and safeParseAsync
2 participants