Skip to content

fix(crashlytics): serialize INT64_MIN without overflow - #16773

Open
dajiaohuang wants to merge 3 commits into
firebase:mainfrom
dajiaohuang:fix/crashlytics-int64-min
Open

dajiaohuang wants to merge 3 commits into
firebase:mainfrom
dajiaohuang:fix/crashlytics-int64-min

Conversation

@dajiaohuang

@dajiaohuang dajiaohuang commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Avoid signed overflow in both int64_t writer paths using unsigned magnitude arithmetic, including INT64_MIN. The normal printed value was already correct; this change removes undefined behavior.
  • Keep buffered/unbuffered JSON regression coverage with the corrected hash-start fixture.
  • Record overflow avoidance under Unreleased with fix(crashlytics): serialize INT64_MIN without overflow #16773.

Validation

  • clang-format 23.1.2 and git diff --check pass for the changed files.
  • Actual pre-PR signed writer bodies compiled with Linux UBSan reproduce INT64_MIN overflow; both updated bodies pass 10 boundary cases. Storage and unsigned-output helpers were stubbed, so this is focused sanitizer evidence.
  • At source 63a828c, the upstream Catalyst FirebaseCrashlytics-Unit-unit run executed 218 tests with zero failures, including testMinInt64: actual XCTest log.
  • The ordinary XCTest pass verifies serialization and the corrected fixture; the before/after UBSan result establishes the overflow distinction.

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@paulb777

paulb777 commented Oct 1, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution! A few housekeeping items:

  • CHANGELOG: The entry in Crashlytics/CHANGELOG.md is under # 13.0.0, which has already shipped. Please move it under a # Unreleased heading at the top of the file (add the heading if it isn't there yet).
  • PR number: end the entry with this PR's number, e.g. - [fixed] Description. (#16773).
  • Formatting: after updating, please run scripts/style.sh so the infra.check job passes. It needs clang-format 23 and swiftformat (see scripts/setup_check.sh). If you can't run it locally, the infra.check log lists the files that need formatting.

@paulb777 paulb777 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. Negating INT64_MIN is undefined behavior, so this is a fair cleanup. In practice, though, the written output was already -9223372036854775808 (only UBSan would flag it). Following up on my earlier comment: please reword the CHANGELOG entry to match (e.g. "Avoid signed integer overflow when serializing INT64_MIN"), or drop it.

CI shows testMinInt64 failing; the cause is inline. The other catalyst failure is the FIRCLSContextManagerTests crash fixed in #16776. Since this and #16772 both touch FIRCLSFile.m, feel free to fold this into #16772.

Comment thread Crashlytics/UnitTests/FIRCLSFileTests.m
Comment thread Crashlytics/Crashlytics/Helpers/FIRCLSFile.m Outdated
@dajiaohuang

Copy link
Copy Markdown
Contributor Author

The JSON regression already has the missing FIRCLSFileWriteHashStart call from the prior follow-up. Both signed writer paths now use the suggested unsigned subtraction, and the changelog is under Unreleased with #16773 and describes avoiding signed overflow rather than changing the already-correct printed value. The changed source/test files pass clang-format 23.1.2 and git diff --check.

For the requested sanitizer distinction, I compiled the actual pre-PR and updated signed writer function bodies on Linux with UBSan and no recovery. The pre-PR INT64_MIN path reports signed overflow; both updated writer functions pass INT64_MIN, INT64_MAX, -1, 0 and 1 (10 cases). The storage and unsigned-output helpers were stubbed for this focused test; it is not a full Crashlytics/XCTest execution. Native Apple XCTest remains for CI. I kept this existing PR separate from #16772 so the overflow change stays independently reviewable.

@paulb777

paulb777 commented Oct 2, 2026

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a signed integer overflow issue when serializing INT64_MIN by casting the value to uint64_t before computing its magnitude, and adds corresponding unit tests. Feedback suggests refactoring the magnitude assignment in FIRCLSFileWriteInt64 and FIRCLSFileFDWriteInt64 to use an if-else block with idiomatic unary negation instead of redundant initialization and subtraction from zero. Additionally, it is recommended to use INT64_MIN directly in the unit test assertion for better readability.

Comment thread Crashlytics/Crashlytics/Helpers/FIRCLSFile.m
Comment thread Crashlytics/Crashlytics/Helpers/FIRCLSFile.m
Comment thread Crashlytics/UnitTests/FIRCLSFileTests.m

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants