artifacts / AFCache

AFCache is an HTTP cache for iOS and OSX seeking towards full RFC2616 compliance
Apache License 2.0
361 stars 43 forks source link

EXC_BAD_ACCESS on iPhone #2

Closed miclee closed 9 years ago

miclee commented 13 years ago

Hi,

Found a problem when using AFURLCache on iPhone (simulator or device, IOS 4.1).

Steps to repeat:

  1. Specify the NSURLCache

    AFURLCache* cache = [[[AFURLCache alloc] initWithMemoryCapacity:0  diskCapacity:0 diskPath:@""] autorelease];
    [NSURLCache setSharedURLCache:cache];
  2. Navigate UIWebView to http://www.google.com/

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com/"]];
    [webView loadRequest:request];
  3. Click the Image link at the top-left will result in EXC_BAD_ACCESS. (Sometimes you need to click 'Image' and 'Web' back and forth until AFURLCache tries to actually load a page from the cache.)

The AFURLCache works fine on many sites. One thing that looks suspicious on Google.com is that there is a file with content type: text/cache-manifest.

Mic

artifacts commented 13 years ago

I think your problem might orginate in data URLs that google uses for some images. http://en.wikipedia.org/wiki/Data_URI_scheme

I'm investigating a similiar issue where an EXC_BAD_ACCESS occures in copyConstantHeaderFieldValue somewhere deep in the NSURL loading framework. Not sure yet if it's the same problem. Debugging is quite hard since no language exception is thrown, but a machine exception.

Some readings:

https://devforums.apple.com/message/328401 http://stackoverflow.com/questions/916718/nsurlconnection-crashing-under-10-5-7 https://devforums.apple.com/message/325237

artifacts commented 13 years ago

After a longer debugging session I am convinced, that this is an iOS Bug introduced in iOS4. The scenario:

At this point, somewhere in the deeps of Apple's CoreFoundation url connection and loading frameworks a machine exception occures when some routine is tryging to access the HTTP header fields. Since no obj-c Exception is thrown and I have no zombie or other useful debugging information, I'm not able to fix anything there. The Problem only occures when UIWebView tries to load resources via ajax.

Next steps:

artifacts commented 13 years ago

addendum: Why iOS4 ? I have a report from a developer who hat a similar issue in iOS4. Compiling against iOS3 SDK solved the problem. I did not try to reproduce that yet.

chlorell commented 13 years ago

i have a similar problem. not exactly with uiwebview, but i get a segfault in the same place. however there is something which may help: when i use AFCache - when NSURLConnection calls - (void)connection:(NSURLConnection )theConnection didReceiveResponse:(NSURLResponse )response - the response isn't a NSHTTPURLResponse object. If i change it in AFURLCache.m to store NSHTTPURLResponse, somehow i still get NSURLResponse object.

orff commented 13 years ago

Did anyone make headway on this bug. I am looking to integrate AFCache into my project, but this bug is a pretty severe limitation for me. I have user inputted web URLS. google.com is bound to come up ;-)

Chlorell, did your patch at least stop the bad access crashing ? The page loads up in a WebView. The crash happens after a render, so I would be happy for now with just a way to stop the exception.

chlorell commented 13 years ago

nope, i justed narrowed the group of sites which are managed by AFCache ;)

artifacts commented 9 years ago

see https://github.com/artifacts/AFCache/issues/9