Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Parsing Methods Type Safe #1040

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ankit-thanekar007
Copy link
Contributor

PrebidSDK Expects Passthrough as an Array on auction response. But it's possible for it to come in as a dictionary from Prebid Server.

Consider this as an example

    NSMutableDictionary *jsonDictionary = [NSMutableDictionary new];
    
    jsonDictionary[@"passthrough"] = @{@"Test1" : @"Passthrough", @"Test2" : @"Crash"};
    
    NSArray<PBMJsonDictionary*> * const passthroughDics = jsonDictionary[@"passthrough"];

    if (passthroughDics) {
        for(PBMJsonDictionary *nextDic in passthroughDics) {
            if ([nextDic isKindOfClass:[NSString class]]) {
                NSLog(@"is String");
            }else if ([nextDic isKindOfClass:[NSArray class]]) {
                NSLog(@"is Array");
            }else if ([nextDic isKindOfClass:[PBMJsonDictionary class]]) {
                NSLog(@"is PBMJsonDictionary");
            }
        }
    }

Here jsonDictionary[@"passthrough"]; is coming in as a dictionary.

When this line executes
NSArray<PBMJsonDictionary*> * const passthroughDics = jsonDictionary[@"passthrough"];
it sets passthroughDics as a NSDictionary

Due to which nextDic in for(PBMJsonDictionary *nextDic in passthroughDics) { is set as NSString

The next line in PrebidSDK is

PBMORTBExtPrebidPassthrough * const nextPassthrough = [[PBMORTBExtPrebidPassthrough alloc] initWithJsonDictionary:nextDic];

which calls init for PBMORTBExtPrebidPassthrough where it executes this line _type = jsonDictionary[@"type"];

This line tries to subscript type inside a NSString which leads to this crash

-[__NSCFString objectForKeyedSubscript:]: unrecognized selector sent to instance 0x300dad3b0

Screenshot 2024-08-21 at 19 55 38

Approach --> We make sure to check for the expected class before accessing or initializing the objects.

@ankit-thanekar007
Copy link
Contributor Author

@jsligh @YuriyVelichkoPI

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.

1 participant