tarkit icon indicating copy to clipboard operation
tarkit copied to clipboard

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

Open QF-ZhouCheng opened this issue 9 years ago • 10 comments

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.

QF-ZhouCheng avatar Jan 26 '16 09:01 QF-ZhouCheng

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

daltoniam avatar Jan 27 '16 02:01 daltoniam

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

QF-ZhouCheng avatar Jan 27 '16 03:01 QF-ZhouCheng

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.

daltoniam avatar Jan 27 '16 03:01 daltoniam

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)

QF-ZhouCheng avatar Jan 27 '16 03:01 QF-ZhouCheng

I got the same problem.

The error will trigger the crash.

Here is my stack trace.

image

image

image

jinzhubaofu avatar Feb 02 '16 03:02 jinzhubaofu

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];
}

jinzhubaofu avatar Feb 02 '16 03:02 jinzhubaofu

@jinzhubaofu let me try.

QF-ZhouCheng avatar Feb 02 '16 05:02 QF-ZhouCheng

@jinzhubaofu it's helpful to me!

khzliu avatar Sep 26 '16 07:09 khzliu

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);
                    }
                }

fuji246 avatar Aug 17 '18 16:08 fuji246

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)

ConfusedVorlon avatar May 22 '20 15:05 ConfusedVorlon