From 8df1f091f86812fb9101b8b86752fc72cb8fe575 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Wed, 2 Nov 2022 11:06:23 +0100 Subject: [PATCH 1/3] Update SentryCrashJSONCodec.c --- Sources/SentryCrash/Recording/Tools/SentryCrashJSONCodec.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/SentryCrash/Recording/Tools/SentryCrashJSONCodec.c b/Sources/SentryCrash/Recording/Tools/SentryCrashJSONCodec.c index ab5e488cc78..d2f231cefd5 100644 --- a/Sources/SentryCrash/Recording/Tools/SentryCrashJSONCodec.c +++ b/Sources/SentryCrash/Recording/Tools/SentryCrashJSONCodec.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -311,6 +312,10 @@ int sentrycrashjson_addFloatingPointElement( SentryCrashJSONEncodeContext *const context, const char *const name, double value) { + if (isnan(value)) { + return sentrycrashjson_addNullElement(context, name); + } + int result = sentrycrashjson_beginElement(context, name); unlikely_if(result != SentryCrashJSON_OK) { return result; } char buff[50]; From d23d1b3db51400447185fdde4dc1bbc7bceaca17 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Wed, 2 Nov 2022 11:24:03 +0100 Subject: [PATCH 2/3] Update SentryCrashJSONCodec_Tests.m --- .../SentryCrash/SentryCrashJSONCodec_Tests.m | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Tests/SentryTests/SentryCrash/SentryCrashJSONCodec_Tests.m b/Tests/SentryTests/SentryCrash/SentryCrashJSONCodec_Tests.m index aebf3439eae..838f4001d9e 100644 --- a/Tests/SentryTests/SentryCrash/SentryCrashJSONCodec_Tests.m +++ b/Tests/SentryTests/SentryCrash/SentryCrashJSONCodec_Tests.m @@ -25,6 +25,7 @@ // #import +#import #import "FileBasedTestCase.h" #import "SentryCrashJSONCodec.h" @@ -798,6 +799,24 @@ - (void)testSerializeDeserializeFloat [[result objectAtIndex:0] floatValue] == [[original objectAtIndex:0] floatValue], @""); } +- (void)testSerializeDeserializeNanFloat +{ + NSError *error = (NSError *)self; + NSString *expected = @"[null]"; + float nanValue = nanf(""); + id original = [NSArray arrayWithObjects:[NSNumber numberWithFloat:nanValue], nil]; + NSString *jsonString = toString([SentryCrashJSONCodec encode:original + options:SentryCrashJSONEncodeOptionSorted + error:&error]); + XCTAssertNotNil(jsonString, @""); + XCTAssertNil(error, @""); + XCTAssertEqualObjects(jsonString, expected, @""); + id result = [SentryCrashJSONCodec decode:toData(jsonString) options:0 error:&error]; + XCTAssertNotNil(result, @""); + XCTAssertNil(error, @""); + XCTAssertTrue([[result objectAtIndex:0] isKindOfClass:[NSNull class]]); +} + - (void)testSerializeDeserializeDouble { NSError *error = (NSError *)self; @@ -816,6 +835,25 @@ - (void)testSerializeDeserializeDouble [[result objectAtIndex:0] floatValue] == [[original objectAtIndex:0] floatValue], @""); } +- (void)testSerializeDeserializeNANDouble +{ + NSError *error = (NSError *)self; + NSString *expected = @"[null]"; + double nanValue = nan(""); + id original = [NSArray arrayWithObjects:[NSNumber numberWithDouble:nanValue], nil]; + + NSString *jsonString = toString([SentryCrashJSONCodec encode:original + options:SentryCrashJSONEncodeOptionSorted + error:&error]); + XCTAssertNotNil(jsonString, @""); + XCTAssertNil(error, @""); + XCTAssertEqualObjects(jsonString, expected, @""); + id result = [SentryCrashJSONCodec decode:toData(jsonString) options:0 error:&error]; + XCTAssertNotNil(result, @""); + XCTAssertNil(error, @""); + XCTAssertTrue([[result objectAtIndex:0] isKindOfClass:[NSNull class]]); +} + - (void)testSerializeDeserializeChar { NSError *error = (NSError *)self; From c0065e53926afb3688f5cec5b410b9ceabc556f7 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Wed, 2 Nov 2022 11:26:16 +0100 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c593980c56..fb081340f9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Stop profiler when app moves to background (#2331) - Clean up old envelopes (#2322) +- SentryCrash writing nan for invalid number (#2348) ## 7.29.0