title: NSRangeException when searching for bytes near end of NSData
body: <p>I want to check the last 2 bytes of files in my app to make sure they are not corrupt .jpg's</p>
  
  <p><code>rangeOfData:options:range:</code> looks like a good option, but I am having a hard time figuring out how to get a proper <code>NSRange</code>.  The range I am looking for is starting near the end of the <code>NSData</code>, up to the end.</p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>NSData *imageData = [NSData dataWithContentsOfFile:filePath];
  NSRange range = {([imageData length]-8),[imageData length]};
  NSString *str = @"FFD9";
  NSData *jpgTest = [str dataUsingEncoding:NSUTF8StringEncoding];
  NSRange found = [imageData rangeOfData:jpgTest options:NSDataSearchBackwards range:range];
  </code></pre>
  
  <p>Here is the error I get:</p>
  
  <blockquote>
    <p>** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSConcreteData rangeOfData:options:range:]: range {14954, 14962} enxceeds data length 14962'</p>
  </blockquote>
  
  <p>How do I properly get the range to search the last few bytes of my <code>NSData</code>?</p>