Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] CRASH: index 0 beyond bounds for empty array #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 28 additions & 14 deletions KTVCocoaHTTPServer/Classes/HTTPConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,17 @@ - (BOOL)parseRangeRequest:(NSString *)rangeHeader withContentLength:(UInt64)cont
// Note: The range is inclusive. So 0-1 has a length of 2 bytes.

if(r1 > r2) return NO;
if(r2 >= contentLength) return NO;

[ranges addObject:[NSValue valueWithDDRange:DDMakeRange(r1, r2 - r1 + 1)]];
/*
modify by robbin([email protected])
old code : if(r2 >= contentLength) return NO;
new code : below
via : https://github.com/robbiehanson/CocoaHTTPServer/issues/78
*/
if(r2 >= contentLength) {
r2 = contentLength - 1;
}

[ranges addObject:[NSValue valueWithDDRange:DDMakeRange(r1, r2 - r1 + 1)]];
}
}
}
Expand Down Expand Up @@ -2516,17 +2524,23 @@ - (void)responseHasAvailableData:(NSObject<HTTPResponse> *)sender
}
else
{
if (ranges == nil)
{
[self continueSendingStandardResponseBody];
}
else
{
if ([ranges count] == 1)
[self continueSendingSingleRangeResponseBody];
else
[self continueSendingMultiRangeResponseBody];
}
/*
modify by robbin([email protected])
old code : if ([ranges count] < 1)
new code : below
via : https://github.com/robbiehanson/CocoaHTTPServer/issues/78
*/
if (!ranges || [ranges count] < 1)
{
[self continueSendingStandardResponseBody];
}
else
{
if ([ranges count] == 1)
[self continueSendingSingleRangeResponseBody];
else
[self continueSendingMultiRangeResponseBody];
}
}
}});
}
Expand Down