daltoniam / tarkit

untar and tar files on iOS and OS X. Also supports gzip tars.
Apache License 2.0
89 stars 25 forks source link

call method:"decompressFileAtPath:toPath:error:" crash #10

Open QF-ZhouCheng opened 8 years ago

QF-ZhouCheng commented 8 years ago

when call the method and give a error parameters will crash.

like this:

NSError *decompressError = nil;
[DCTar decompressFileAtPath:strPath1 toPath:strPath2 error:&decompressError];

you can try it.

daltoniam commented 8 years ago

Ok, this doesn't give us anything to go off. Can you provide the crash you are getting? What is strPath1 and strPath2?

QF-ZhouCheng commented 8 years ago

The code like this is ok:

[QFZIP decompressFileAtPath:strPath1 toPath:strPath2 error:nil];

and the code like this will crash:

NSError *decompressError = nil;
[QFZIP decompressFileAtPath:strPath1 toPath:strPath2 error:&decompressError];

Just give a error variable as the parameter.

@daltoniam

strPath1 = @"/var/mobile/Containers/Data/Application/A94B4EAC-5875-47AB-AC21-8437E72C6B78/Documents/Data/DownloadData.tar.gz"
strPath2 = @"/var/mobile/Containers/Data/Application/A94B4EAC-5875-47AB-AC21-8437E72C6B78/Documents/Data"

and crash info is:

Incident Identifier: 760F6AD2-6BC7-4E4C-A802-8FC60312ADF5
CrashReporter Key:   6971d8ae264d1f2f519b9ac7bbd6b1dba7a9a8a2
Hardware Model:      iPhone7,2
OS Version:          iPhone OS 8.3 (12F70)
Kernel version:      Darwin Kernel Version 14.0.0: Sun Mar 29 19:42:54 PDT 2015; root:xnu-2784.20.34~2/RELEASE_ARM64_T7000
Date:                2016-01-26 17:19:01 +0800
Exception Code:      0xd1510c8d
Reason:              Step count has rolled back!!

Thermal data unavailable

Frontmost process PID:    3194
Frontmost process PID:    54
Stackshot trace buffer size too small, trying again with 524288 bytes.
Jetsam Level:              0
Free Pages:            18232
Active Pages:         134789
Inactive Pages:        13616
Purgeable Pages:         796
Wired Pages:           52444
Speculative Pages:     17507
Throttled Pages:           0
File-backed Pages:     83496
Compressions:          92138
Decompressions:        13727
Compressor Size:       16028
Busy Buffer Count:         1
Pages Wanted:              0
Pages Reclaimed:           0
daltoniam commented 8 years ago

Hmm interesting. Do you have a stack trace? Not sure why providing a error would cause a crash, I don't see anything off hand that would cause that.

QF-ZhouCheng commented 8 years ago

looks like not stack trace, I used NSURLSession to download the gzip file from server, and then decompress it, the stack trace just like this:

![screen shot 2016-01-27 at 11 43 36 am](https://cloud.githubusercontent.com/assets/13899656/12603209/89027468-c4eb-11e5-9903-b1276caf4f27.png)
![screen shot 2016-01-27 at 11 43 19 am](https://cloud.githubusercontent.com/assets/13899656/12603212/9164a6da-c4eb-11e5-917d-09c4a43c64d6.png)
jinzhubaofu commented 8 years ago

I got the same problem.

The error will trigger the crash.

Here is my stack trace.

image

image

image

jinzhubaofu commented 8 years ago

Hi, I guess this error passed down in a autoreleasepool maybe the reason.

https://github.com/daltoniam/tarkit/blob/master/DCTar.m#L315

I changed it to nill and it will stop crashing.

if(size == 0) {
   [@"" writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];
}
QF-ZhouCheng commented 8 years ago

@jinzhubaofu let me try.

khzliu commented 8 years ago

@jinzhubaofu it's helpful to me!

fuji246 commented 6 years ago

would be better to change that to

                if(size == 0) {
                    NSError *writeError;
                    BOOL ret = [@"" writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&writeError];
                    if (!ret) {
                        NSLog(@"UNTAR - error during creating a directrory for a file - %@", writeError);
                    }
                }
ConfusedVorlon commented 4 years ago

for anyone coming to this from swift. The error param is automatically 'scooped' into the system, so you can't just set it to nil.

I ended up just creating an objective C helper

//DCTarHelper.h
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface DCTarHelper : NSObject

+(BOOL)decompressFileAtPath:(NSString*)filePath toPath:(NSString*)path;

@end

NS_ASSUME_NONNULL_END
//DCTarHelper.m
#import "DCTarHelper.h"
#import <tarkit/DCTar.h>

@implementation DCTarHelper

+(BOOL)decompressFileAtPath:(NSString*)filePath toPath:(NSString*)path {
    return [DCTar decompressFileAtPath:filePath toPath:path error:nil];
}

@end

which you can then call from Swift

DCTarHelper.decompressFile(atPath: source, toPath: destination)