Skip to content

JSON number parsing bug fix - #3921

Open
pulimsr wants to merge 3 commits into
mainfrom
fix-json-number-parsing
Open

JSON number parsing bug fix#3921
pulimsr wants to merge 3 commits into
mainfrom
fix-json-number-parsing

Conversation

@pulimsr

@pulimsr pulimsr commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Fix JSON number parsing edge cases in aws-cpp-sdk-core

  • Serialize large integer literals without the fixed-size buffer limit.
  • Saturate out-of-range double→int64 conversions instead of undefined behavior.
  • Decode scientific-notation integers correctly.

Check all that applies:

  • Did a review by yourself.
  • Added proper tests to cover this PR. (If tests are not applicable, explain.)
  • Checked if this PR is a breaking (APIs have been changed) change.
  • Checked if this PR will not introduce cross-platform inconsistent behavior.
  • Checked if this PR would require a ReadMe/Wiki update.

Check which platforms you have built SDK on to verify the correctness of this PR.

  • Linux
  • Windows
  • Android
  • MacOS
  • IOS
  • Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@pulimsr
pulimsr force-pushed the fix-json-number-parsing branch from bbf9531 to bbe7024 Compare September 8, 2026 18:54
@pulimsr
pulimsr force-pushed the fix-json-number-parsing branch from bbe7024 to e937d92 Compare September 8, 2026 20:27

namespace
{
const double LLONG_MIN_AS_DOUBLE = -9223372036854775808.0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lets no use actual hard coded numbers, those are fragile, use numeric limits where you can

constexpr double LLONG_MIN_AS_DOUBLE =
    static_cast<double>(std::numeric_limits<int64_t>::min());
constexpr double LLONG_MAX_PLUS_ONE =
    -static_cast<double>(std::numeric_limits<int64_t>::min());


namespace
{
const double LLONG_MIN_AS_DOUBLE = -9223372036854775808.0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same about using numerical limits

const double LLONG_MIN_AS_DOUBLE = -9223372036854775808.0;
const double LLONG_MAX_PLUS_ONE = 9223372036854775808.0;

bool IsRepresentableAsInt64(double value)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

these functions appear copy and pasted twice lets move them into a header that is not installed/part of the public API. somewhere in aws/core/utils, maybe under a new directory that is build alongside the SDK but not installed. numeric utils or something of the like

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.

2 participants