Skip to content

Commit

Permalink
Fixed another assertion-failure when a _bulk_get download can’t parse…
Browse files Browse the repository at this point in the history
… a JSON doc

Found a piece that was missing from the prior fix 24f6381. The same assertion failure was occurring,
under slightly different circumstances.
Fixes couchbase#288 (speculatively). Also see couchbase#271, couchbase#232.
  • Loading branch information
snej authored and Igor Evsukov committed Aug 27, 2014
1 parent 469edd4 commit 0568af5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Source/CBLMultipartReader.m
Expand Up @@ -146,15 +146,17 @@ - (void) deleteUpThrough: (NSRange)r {
[_buffer replaceBytesInRange: NSMakeRange(0, NSMaxRange(r)) withBytes: NULL length: 0];
}

- (void) trimBuffer {
- (BOOL) appendAndTrimBuffer {
NSUInteger bufLen = _buffer.length;
NSUInteger boundaryLen = _boundary.length;
if (bufLen > boundaryLen) {
// Leave enough bytes in _buffer that we can find an incomplete boundary string
NSRange trim = NSMakeRange(0, bufLen - boundaryLen);
[_delegate appendToPart: [_buffer subdataWithRange: trim]];
if (![_delegate appendToPart: [_buffer subdataWithRange: trim]])
return NO;
[self deleteUpThrough: trim];
}
return YES;
}


Expand Down Expand Up @@ -221,7 +223,10 @@ - (void) appendData: (NSData*)data {
[self deleteUpThrough: r];
nextState = kInHeaders;
} else {
[self trimBuffer];
if (![self appendAndTrimBuffer]) {
[self stop];
break;
}
}
break;
}
Expand Down

0 comments on commit 0568af5

Please sign in to comment.