Question

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;
Was it helpful?

Solution

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;

}

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top