Skip to content

Commit

Permalink
ios: add ASCII fallback if SetNSError encounters invalid UTF8 error s…
Browse files Browse the repository at this point in the history
…tring

This adds a layer of security to prevent nil crashes in case there are
more cases with invalid UTF8 error messages. This supersedes zxing-cpp#717.
  • Loading branch information
axxel committed Feb 8, 2024
1 parent 6ab17fd commit 0eaeb1d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions wrappers/ios/Sources/Wrapper/ZXIErrors.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ void SetNSError(NSError *__autoreleasing _Nullable* error,
}
NSString *errorDescription = @"Unknown C++ error";
if (message && strlen(message) > 0) {
try {
errorDescription = [NSString stringWithUTF8String: message];
} catch (NSException *exception) {
errorDescription = @"Unknown ObjC error";
errorDescription = [NSString stringWithUTF8String: message];
if (errorDescription == nil) {
[NSString stringWithCString: message encoding: NSASCIIStringEncoding];

This comment has been minimized.

Copy link
@markusfisch

markusfisch Feb 8, 2024

@axxel Well, I think this should be assigned to errorDescription 😉

This comment has been minimized.

Copy link
@axxel

axxel Feb 8, 2024

Author Owner

Öhm... how can I possibly spin this in a way to make me look less of a fool? :-P

Option 1: YES! Congrats, you passed the test.
Option 2: I wanted to make sure you don't feel offended by my comment.
Option 3: I never said, I know anything about Objective-C.

Fix will follow, thanks! :)

This comment has been minimized.

Copy link
@markusfisch

markusfisch Feb 8, 2024

I like Option 1 😂 One thing I achieved today! 😉

}
}
NSDictionary *userInfo = @{ NSLocalizedDescriptionKey: errorDescription };
Expand Down

0 comments on commit 0eaeb1d

Please sign in to comment.