Revision: 5893
http://skim-app.svn.sourceforge.net/skim-app/?rev=5893&view=rev
Author: hofman
Date: 2009-10-16 12:32:27 +0000 (Fri, 16 Oct 2009)
Log Message:
-----------
use correct length of data to find and check for zero length data before
getting its bytes
Modified Paths:
--------------
trunk/NSData_SKExtensions.m
trunk/SKMainDocument.m
Modified: trunk/NSData_SKExtensions.m
===================================================================
--- trunk/NSData_SKExtensions.m 2009-10-16 08:51:44 UTC (rev 5892)
+++ trunk/NSData_SKExtensions.m 2009-10-16 12:32:27 UTC (rev 5893)
@@ -47,20 +47,20 @@
- (NSRange)Leopard_rangeOfData:(NSData *)dataToFind
options:(NSDataSearchOptions)mask range:(NSRange)searchRange {
NSUInteger patternLength = [dataToFind length];
NSUInteger selfLength = [self length];
+
if (searchRange.location > selfLength || NSMaxRange(searchRange) >
selfLength)
[NSException raise:NSRangeException format:@"Range {%lu,%lu} exceeds
length %lu", (unsigned long)searchRange.location, (unsigned
long)searchRange.length, (unsigned long)selfLength];
+ // This test is a nice shortcut, but it's also necessary to avoid
crashing: zero-length NSDatas will sometimes(?) return NULL for their bytes
pointer, and the resulting pointer arithmetic can underflow.
+ if (patternLength == 0 || patternLength > searchRange.length)
+ return NSMakeRange(NSNotFound, 0);
+
const void *patternBytes = [dataToFind bytes];
const unsigned char *selfBufferStart, *selfPtr, *selfPtrEnd, *selfPtrMax;
const unsigned char firstPatternByte = *(const char *)patternBytes;
BOOL backward = (mask & NSDataSearchBackwards) != 0;
BOOL anchored = (mask & NSDataSearchAnchored) != 0;
- if (patternLength == 0 || patternLength > searchRange.length) {
- // This test is a nice shortcut, but it's also necessary to avoid
crashing: zero-length CFDatas will sometimes(?) return NULL for their bytes
pointer, and the resulting pointer arithmetic can underflow.
- return NSMakeRange(NSNotFound, 0);
- }
-
selfBufferStart = [self bytes];
selfPtrMax = selfBufferStart + NSMaxRange(searchRange) + 1 - patternLength;
if (backward) {
@@ -249,6 +249,7 @@
}
+ (void)load {
+ // this should do nothing on Snow Leopard
SKAddInstanceMethodImplementationFromSelector(self,
@selector(rangeOfData:options:range:),
@selector(Leopard_rangeOfData:options:range:));
}
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2009-10-16 08:51:44 UTC (rev 5892)
+++ trunk/SKMainDocument.m 2009-10-16 12:32:27 UTC (rev 5893)
@@ -1692,7 +1692,7 @@
if (trailerRange.location != NSNotFound) {
NSRange IDRange = [pdfData rangeOfData:[NSData dataWithBytes:"/ID"
length:3] options:0 range:SKRangeBetweenRanges(trailerRange, EOFRange)];
if (IDRange.location != NSNotFound) {
- NSRange startArrayRange = [pdfData rangeOfData:[NSData
dataWithBytes:"[" length:0] options:0 range:SKRangeBetweenRanges(IDRange,
EOFRange)];
+ NSRange startArrayRange = [pdfData rangeOfData:[NSData
dataWithBytes:"[" length:1] options:0 range:SKRangeBetweenRanges(IDRange,
EOFRange)];
if (startArrayRange.location != NSNotFound) {
NSRange endArrayRange = [pdfData rangeOfData:[NSData
dataWithBytes:"]" length:1] options:0
range:SKRangeBetweenRanges(startArrayRange, EOFRange)];
if (endArrayRange.location != NSNotFound) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit