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

JSON::PullParser overflow handling #8698

Merged
merged 4 commits into from
Feb 8, 2020
Merged

JSON::PullParser overflow handling #8698

merged 4 commits into from
Feb 8, 2020

Conversation

kimburgess
Copy link
Contributor

Changes behaviour of:

  • JSON::PullParser#read? to either fully read into the specified type, or return nil
  • Numeric primitive instantiation from JSON::PullParser to raise a JSON::ParseException wrapping an OverflowError in the case of overflow.

Fixes #8694

Captures OverfowErrors caused when attemting to read into an
incompatible integer type and wraps in a JSON::ParseException with
location context.
Adjusts behaviour to return nil in case of a numeric overflow when
reading into numeric types.
@bcardiff bcardiff added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:serialization labels Jan 18, 2020
@straight-shoota
Copy link
Member

Could you please add specs for read? as well?

Copy link
Member

@RX14 RX14 left a comment

Choose a reason for hiding this comment

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

There should be Int#to_i32? etc. to return nil if a cast fails. But that's another thing and i think needs compiler support.

Fixes and uncaught exception that would occur when reading integer
values outside the bounds of a UInt64.
@asterite asterite added this to the 0.33.0 milestone Feb 8, 2020
@asterite asterite merged commit 57fa02e into crystal-lang:master Feb 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:serialization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON::PullParser numeric overflow behaviour
5 participants