1

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;
Florik
  • 1,260
  • 1
  • 12
  • 20

2 Answers2

1

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;

}

huang ke
  • 26
  • 3
0

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.

Community
  • 1
  • 1
Dov
  • 15,530
  • 13
  • 76
  • 177
  • i've found the issue, but i could not resolve it, i remaked UNRAR4IOS object so just it returns me throw, and in try statement i get the error !! – Florik Jul 10 '12 at 12:58
  • There is no way in Cocoa to catch unix signals, like `SIGSEGV`. – Dov Jul 10 '12 at 13:00
  • you should rewrite unrar4iOS method extract stream: – Florik Jul 10 '12 at 13:17
  • while ((RHCode = RARReadHeaderEx(_rarFile, header)) == 0) { NSString *_filename = [NSString stringWithCString:header->FileName encoding:NSASCIIStringEncoding]; if ([_filename isEqualToString:aFile]) { length = header->UnpSize; break; } else { if ((PFCode = RARProcessFile(_rarFile, RAR_SKIP, NULL, NULL)) != 0) { [self _unrarCloseFile]; return nil; } } } – Florik Jul 10 '12 at 13:17
  • in the .mm file, extract stream method, there is no error chech – Florik Jul 10 '12 at 13:18
  • i added thew else to find if the erro persists, it should throw me back, with an exception !!! – Florik Jul 10 '12 at 13:19
  • It seems like you've performed some useful troubleshooting steps, but it's difficult to read your code in comments. Can you update your question to include the code you modified in `Unrar4iOS`? – Dov Jul 11 '12 at 01:29
  • - (BOOL)rarOpenFile:(NSString *)rarFile mode:(NSInteger)mode – Florik Jul 25 '12 at 12:29
  • 1
    and exactly after RAROpenArchiveEx(flags); you get the result in flags->OpenResult, it must return a 0 if its ok, otherwise its an error, shown below: ERAR_END_ARCHIVE = 10; ERAR_NO_MEMORY = 11; ERAR_BAD_DATA = 12; ERAR_BAD_ARCHIVE = 13; ERAR_UNKNOWN_FORMAT = 14; ERAR_EOPEN = 15; ERAR_ECREATE = 16; ERAR_ECLOSE = 17; ERAR_EREAD = 18; ERAR_EWRITE = 19; ERAR_SMALL_BUF = 20; ERAR_UNKNOWN = 21; – Florik Jul 25 '12 at 12:33