Aws-sdk-ios: Crash in -[AWSSignature nextChunk] (line 652)

Created on 16 Dec 2015  路  10Comments  路  Source: aws-amplify/aws-sdk-ios

If the call to -[NSInputStream read:maxLength:] returns a negative number due to an error, it will cause a crash when calling +[NSData dataWithBytesNoCopy:length:]

Fatal Exception: NSInvalidArgumentException
*** -[NSConcreteData initWithBytes:length:copy:deallocator:]: absurd length: 18446744073709551615, maximum size: 9223372036854775808 bytes

    NSInteger read = [self.stream read:chunkBuffer maxLength:defaultChunkSize];

    // mark end of stream if no data is read
    self.endOfStream = (read <= 0);

    NSData *data = [NSData dataWithBytesNoCopy:chunkBuffer length:read];
question

Most helpful comment

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '** -[NSConcreteData initWithBytes:length:copy:deallocator:]: absurd length: 18446744073709551615, maximum size: 9223372036854775808 bytes'
*
* First throw call stack:

How to resolve it ?? using (xcode 7.3 , swift ), i also updated Plist as instructed

All 10 comments

Can you share a code snippet to reproduce the issue? Thanks.

Unfortunately, I don't have an easy way to replicate the crash. I believe, in our case, the crash due to the file be protected on the file system with NSFileProtectionComplete. After the device is locked for 10 seconds, the file will become unaccessible and thus attempting to read from it will fail. This will return a negative number stored in the "read" variable. Passing signed value as an NSUInteger will cause it to look like an extremely large positive number. Note: you have to do this on an physical device with a passcode set. File protection isn't available in the iOS simulator. I can whip up a quick app to reproduce this if needed. Let me know.

I see, I got the better understanding of the situation. It seems like you are using AWSS3 or AWSS3TransferManager. Does it help if you use AWSS3TransferUtility? I believe AWSS3TransferUtility fails more gracefully. We will phase out AWSS3TransferManager in favor of AWSS3TransferUtility in the coming months.

We are indeed still using AWSS3TransferManager (we actually already have background upload/download working without using AWSS3TransferUtility), but if AWSS3TransferUtility uses AWSSignature, the problem will still occur.

Here's a short program to illustrate the issue:

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {

        NSInputStream *input = [NSInputStream inputStreamWithFileAtPath:@"/this/file/does/not/exist"];
        [input open];

        uint8_t *buffer = calloc(1, sizeof(uint8_t));
        NSInteger read = [input read:buffer maxLength:1];
        NSData *data = [NSData dataWithBytesNoCopy:buffer length:read];
        NSLog(@"we shouldn't make it this far: %@", data);
        [input close];
        free(buffer);
    }
    return 0;
}

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSConcreteData initWithBytes:length:copy:deallocator:]: absurd length: 18446744073709551615, maximum size: 9223372036854775808 bytes'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff8a991ae2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff8599073c objc_exception_throw + 48
2 CoreFoundation 0x00007fff8a99198d +[NSException raise:format:] + 205
3 Foundation 0x00007fff85d070d5 -[NSConcreteData initWithBytes:length:copy:deallocator:] + 130
4 Foundation 0x00007fff85d06ef0 -[NSData(NSData) initWithBytesNoCopy:length:] + 37
5 Foundation 0x00007fff85d06e13 +[NSData(NSData) dataWithBytesNoCopy:length:] + 54
6 AWSCrash 0x0000000100000e20 main + 192
7 libdyld.dylib 0x00007fff879215ad start + 1
8 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

AWSS3TransferUtility does not use AWSSignature in the background.

I'll give AWSS3TransferUtility a chance when I have time.

Looks like AWSS3TransferUtility is still in beta. Any idea when it'll be ready for the prime time?

While we cannot discuss our future plans, AWSS3TransferUtility has a few limitations as described here. If it suits your use case, it is more stable and reliable than AWSS3TransferManager.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '** -[NSConcreteData initWithBytes:length:copy:deallocator:]: absurd length: 18446744073709551615, maximum size: 9223372036854775808 bytes'
*
* First throw call stack:

How to resolve it ?? using (xcode 7.3 , swift ), i also updated Plist as instructed

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[NSConcreteData initWithBytes:length:copy:deallocator:]: absurd length: 18446744073709551615, maximum size: 9223372036854775808 bytes'

How to resolve it ?? using (xcode 8.0 , swift 3.0),and what is need to update in infoplist. lets me know.
Thanks

Was this page helpful?
0 / 5 - 0 ratings