Fix Cap'n Proto serialization of unsigned integer types#635
Fix Cap'n Proto serialization of unsigned integer types#635lixin-wei wants to merge 1 commit intogetml:mainfrom
Conversation
The Writer was casting all integral types to std::int64_t, which causes uint64_t values like UINT64_MAX to overflow to -1 and trigger a Cap'n Proto assertion: "expected value >= 0". This adds a std::is_unsigned branch (before the std::is_integral fallback) in add_value_to_array, add_value_to_object, and add_value_to_union so unsigned types are cast to std::uint64_t instead. Made-with: Cursor
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug in the Cap'n Proto serialization logic that caused unsigned integer types to be mishandled, resulting in data corruption or runtime errors. The changes introduce proper type-aware casting for unsigned integers and are accompanied by comprehensive new tests to prevent future regressions and ensure data integrity. Highlights
Using Gemini Code AssistThe 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
Customization To customize 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. 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. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a serialization bug for unsigned integer types in the Cap'n Proto writer by introducing a specific handling path for them. The changes are applied consistently across array, object, and union writing functions. The new tests adequately cover the fix. My review includes a suggestion to remove a redundant test case and a recommendation to refactor duplicated code for better maintainability in the future.
|
The failed checks seems not related to my change. |
Summary
serializing
in capnproto will throw:
This PR fixes it.
Test plan
test_uint64tests fail without the fix (verified by reverting and rebuilding)