Skip to content

Commit

Permalink
Fixed crash when stub with very long data and no delay for response
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Loup authored and tibr committed Apr 30, 2014
1 parent 49ab283 commit 712375f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 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 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 712375f

Please sign in to comment.