在线崩溃" remainingData = [data subdataWithRange:NSMakeRange(size,data.length - size)];"

时间:2014-08-01 12:45:43

标签: ios crash nsdata

我正面临崩溃“因未捕获的异常NSRangeException而终止应用”,原因是:

  

' * - [NSSubrangeData subdataWithRange:]:范围{8,565316237}超出   数据长度210204'“

如果有人可以帮助我找到解决方案。

-(NSData *) parseAtom:(MP4Atom **) pAtom fromData:(NSData *) data {
        // Assume it all remains
        NSData *remainingData = data;

        // Data must not be nil
        if( data != nil ) {

            // Length must be at least 8 bytes
            if( data.length > 8 ) {

                // Read type and size
                UInt32 size = [data uint32AtOffset:0];
                NSString *type = [data fourByteStringAtOffset:4];

                // The rest is data
                NSData *atomData = [data subdataWithRange:NSMakeRange(8, size - 8)];

                // Read the atom
                MP4Atom *atom = [MP4Atom mp4AtomWithType: type data:atomData];

                // Get the remaining data
                if( size < data.length) {
                    remainingData = [data subdataWithRange:NSMakeRange(size, data.length - size)];
                } else {
                    remainingData = nil;
                }

                // If we got a valid result...
                if( atom != nil ) {
                    // ... and pAtom was not nil,
                    if( pAtom != nil ) {
                        // assign the atom
                        *pAtom = atom;
                    } else {
                        DDLogCritical( @"pAtom is nil in parseAtom:fromData:");
                    }
                } else {
                    DDLogCritical( @"Failed to parse atom from data in parseAtom:fromData:");
                }
            } else {
                DDLogCritical( @"data is too short (%d) expected at least 8 bytes in parseAtom:fromData:", data.length);
            }
        } else {
            DDLogCritical( @"data is nil in parseAtom:fromData:");
        }
        return remainingData;
    }

0 个答案:

没有答案