Skip to content

fix: UB in SchemaValidator::Double when casting out-of-range doubles#2378

Open
KowalskiThomas wants to merge 1 commit into
Tencent:masterfrom
KowalskiThomas:kowalski/fix-ub-in-schemavalidator-double-when-casting-out-of-range-doubles
Open

fix: UB in SchemaValidator::Double when casting out-of-range doubles#2378
KowalskiThomas wants to merge 1 commit into
Tencent:masterfrom
KowalskiThomas:kowalski/fix-ub-in-schemavalidator-double-when-casting-out-of-range-doubles

Conversation

@KowalskiThomas

@KowalskiThomas KowalskiThomas commented Apr 27, 2026

Copy link
Copy Markdown

What is this PR?

This PR fixes an undefined behaviour happening when trying to cast a double to an integer (int64_t or uint64_t) outside its valid range.

/home/user/rapidjson/include/rapidjson/schema.h:345:50: runtime error: 1e+33 is outside the range of representable values of type 'unsigned long'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /home/user/rapidjson/include/rapidjson/schema.h:345:50 in
MS: 4 ChangeByte-ChangeByte-InsertRepeatedBytes-CrossOver-; base unit: d06ccadf2965827126a941a193346fc522f20a85

The proposed fix is to set the integer representation to 0 if it's outside the valid value range.

The PR also adds a test validating the new behaviour.

@tencent-adm

tencent-adm commented Apr 27, 2026

Copy link
Copy Markdown
Member

CLA assistant check
All committers have signed the CLA.

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