UIWebPDFView removes an observer it didn't register

Originator:johan
Number:rdar://10431759 Date Originated:11-Nov-2011 10:14 AM
Status:Open Resolved:
Product:iOS SDK Product Version:Build 4D199
Classification:Serious bug Reproducible:Always
 
11-Nov-2011 10:14 AM Johan Sorensen:
'pdftest.zip' was successfully uploaded

11-Nov-2011 10:14 AM Johan Sorensen:
Summary:

When using a UIWebView to load up a PDF in the mainbundle, it'll crash when the webview is released with

(gdb) po $eax
Cannot remove an observer <UIWebPDFView 0x6d4a820> for the key path "backgroundImage" from <UIPDFPageView 0x6e36000> because it is not registered as an observer.
(gdb) bt
#0  0x0154acf0 in objc_exception_throw ()
#1  0x01361a78 in +[NSException raise:format:arguments:] ()
#2  0x013619e9 in +[NSException raise:format:] ()
#3  0x00922c94 in -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] ()
#4  0x00922911 in -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] ()
#5  0x0046a8b0 in -[UIWebPDFView _removeBackgroundImageObserverIfNeeded:] ()
#6  0x0046ab7a in -[UIWebPDFView dealloc] ()
#7  0x0155de4d in _objc_rootRelease ()
#8  0x0046e171 in -[UIWebPDFViewHandler clearAllViews] ()
#9  0x0046e030 in -[UIWebPDFViewHandler dealloc] ()
#10 0x0155de4d in _objc_rootRelease ()
#11 0x001c509c in -[UIWebView dealloc] ()
#12 0x001c4e9f in -[UIWebView release] ()
#13 0x00047153 in -[UIView(Hierarchy) removeFromSuperview] ()
#14 0x000431e0 in -[UIView dealloc] ()
#15 0x0155de4d in _objc_rootRelease ()
#16 0x0155de10 in objc_release ()
#17 0x0155ec60 in (anonymous namespace)::AutoreleasePoolPage::pop ()
#18 0x012eded8 in _CFAutoreleasePoolPop ()
#19 0x012f083b in __CFRunLoopRun ()
#20 0x012efdb4 in CFRunLoopRunSpecific ()
#21 0x012efccb in CFRunLoopRunInMode ()
#22 0x012a2879 in GSEventRunModal ()
#23 0x012a293e in GSEventRun ()
#24 0x00010a9b in UIApplicationMain ()
#25 0x00001ac2 in main (argc=1, argv=0xbffff664) at /Users/johan/backyard/pdftest/pdftest/main.m:16

It would appear it attempts to remove an observer for the keypath "backgroundImage" which it didn't actually register for.

This appears to be a iOS5 issue only both in the simulator and device. I can't reproduce it with 4.3

The PDF is loaded with the following code:
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:request];

and it'll crash when [webView release] is called in the viewcontroller's -dealloc

Steps to Reproduce:

Compile and run the attached simplified example project . Click the button to open up the modal webview, hit the close button in that and observe the crashing.

Expected Results:

UIWebView shouldn't crash when rendering a PDF when the webview is deallocated

Actual Results:

UIWebView (nee the internal UIWebPDFView) crashes

Regression:

Unable to render PDFs in practice as it crashes when you're done showing that PDF

Notes:

Example project included with an isolated reproducible application demonstrating the crash

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!