Skip to content

Commit

Permalink
Fixed crash when stub with very long data and no delay for response (f…
Browse files Browse the repository at this point in the history
…ixes #57 #59)
  • Loading branch information
AliSoftware committed May 3, 2014
2 parents 49ab283 + f4127ca commit b3a83e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion OHHTTPStubs/Sources/OHHTTPStubs.m
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ - (void) streamDataForClient:(id<NSURLProtocolClient>)client
timingInfo:timingInfo completion:completion];
});
} else {
uint8_t buffer[chunkSizeToRead];
uint8_t* buffer = (uint8_t*)malloc(sizeof(uint8_t*)*chunkSizeToRead);
NSInteger bytesRead = [inputStream read:buffer maxLength:chunkSizeToRead];
if (bytesRead > 0)
{
Expand All @@ -492,6 +492,7 @@ - (void) streamDataForClient:(id<NSURLProtocolClient>)client
completion(inputStream.streamError);
}
}
free(buffer);
}
}
else
Expand Down
12 changes: 12 additions & 0 deletions OHHTTPStubs/UnitTests/Test Suites/TimingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,16 @@ -(void)test_LongData_RequestTime1_ResponseTime5
[self _testWithData:testData requestTime:1 responseTime:5];
}

-(void)test_VeryLongData_RequestTime1_ResponseTime0
{
static NSUInteger const kDataLength = 609792;
NSMutableData* testData = [NSMutableData dataWithCapacity:kDataLength];
NSData* chunk = [[NSProcessInfo.processInfo globallyUniqueString] dataUsingEncoding:NSUTF8StringEncoding];
while(testData.length<kDataLength)
{
[testData appendData:chunk];
}
[self _testWithData:testData requestTime:1 responseTime:0];
}

@end

0 comments on commit b3a83e8

Please sign in to comment.