Unrar4iOS error, File::tell() throws to asm code, what should I do?

452 views Asked by At

I have an error File::tell() shown in XCode, using Unrar4iOS Framework, when I am calling the method:

-(NSArray)unrarListFiles;

the compiler shows me the a bunch of errors, where the last from stack is ftell, if someone knows, the origin if where probabily i am wrong, plese reply... the full procedure what i want to do is to extrat the int number of files archived, from code below:

int nuberOfPages = 0;
NSLog(@"Filepath: %@", filePath);
Unrar4iOS *_unrar = [[Unrar4iOS alloc] init];
BOOL ok = [_unrar unrarOpenFile:filePath];
if (ok) {

    NSArray *files = [_unrar unrarListFiles];
    for (NSString *filename in files) {
        NSLog(@"File: %@", filename);
    }
    nuberOfPages = files.count;

    [unrar unrarCloseFile];
} else {
    [unrar unrarCloseFile];
}
[_unrar release];
return nuberOfPages;
2

There are 2 answers

0
huang ke On BEST ANSWER

this is because that. in source code.

-(BOOL) unrarOpenFile:(NSString*)rarFile



-(BOOL) unrarCloseFile

the function above. they did not do anything.

this function do real open and real close;

-(NSArray *) unrarListFiles {
int RHCode = 0, PFCode = 0;

    //here  if you opened a file that is not rar.
    //this function RARReadHeaderEx will EXC_BAD_ACCESS (SIGSEGV)
    //so, you can check it return value
[self _unrarOpenFile:filename mode:RAR_OM_LIST];

NSMutableArray *files = [NSMutableArray array];
while ((RHCode = RARReadHeaderEx(_rarFile, header)) == 0) {
    NSString *_filename = [NSString stringWithCString:header->FileName encoding:NSASCIIStringEncoding];
    [files addObject:_filename];

    if ((PFCode = RARProcessFile(_rarFile, RAR_SKIP, NULL, NULL)) != 0) {
        [self _unrarCloseFile];
        return nil;
    }
}

[self _unrarCloseFile];
return files;

}

9
Dov On

I believe this is a bug in Unrar4iOS triggered by reading a corrupt RAR archive (or a file that is not a RAR archive at all). It attempts to read an address on disk that is not part of the archive, and throws an EXC_BAD_ACCESS (SIGSEGV). I posted this as an issue in the GitHub project: https://github.com/ararog/Unrar4iOS/issues/6

Matt Gallagher wrote an article on Cocoa with Love showing how to try to present the error nicely to the user, but that code should not be used to keep your application running, as it may have unpredictable results.

Update: for what it's worth, I forked Unrar4iOS into a new project, UnrarKit, which handles errors using NSError instead of throwing exceptions.