Bug 26764 - Uncaught NOT_FOUND_ERR: DOMException 8 loading empty text file
Summary: Uncaught NOT_FOUND_ERR: DOMException 8 loading empty text file
Status: VERIFIED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Mac OS X 10.5
: P2 Normal
Assignee: Alexey Proskuryakov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-26 16:48 PDT by Jeff Johnson
Modified: 2010-03-10 21:32 PST (History)
1 user (show)

See Also:


Attachments
Sample Xcode project (21.29 KB, application/octet-stream)
2009-06-26 16:49 PDT, Jeff Johnson
no flags Details
proposed fix (3.25 KB, patch)
2009-06-30 04:53 PDT, Alexey Proskuryakov
mitz: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Johnson 2009-06-26 16:48:28 PDT
Overview Description:
Loading an empty text file in a WebView raises an uncaught DOM exception. This occurs both when the .txt file is remote (Content-Length: 0, Content-Type: text/plain) and when the file is local on disk.

Steps to Reproduce:
1. Launch Terminal.app
2. cd Desktop
3. touch empty.txt
4. Open, build, and run attached sample Xcode project MiniBrowser.

Actual Results:
NSLog() statement at MyDocument.m:248 is not run. Instead, the previous statement raises an exception.
MiniBrowser[25271:813] *** WebKit discarded an uncaught exception in the webView:didFinishLoadForFrame: delegate: <DOMException> *** NOT_FOUND_ERR: DOMException 8

Expected Results:
No exception. The NSLog() statement at MyDocument.m:248 is run.

Build Date & Platform:
git commit 9c5a91f35e3f4e4c7c4882ec9dca03044ddb44ca (trunk@45288)

Additional Builds and Platforms:
Stock WebKit on Mac OS X 10.5.7 Build 9J61, Safari 4.0.1 (5530.18)

Additional Information:
The sample Xcode project is based on "/Developer/Examples/WebKit/MiniBrowser" from Xcode 3.1.3. The only changes I made were to set the SDK to 10.5, change the loaded URL to the text file, and add a few lines of code in webView:didFinishLoadForFrame:

		NSView <WebDocumentView> *documentView = [[frame frameView] documentView];
		if ( [documentView conformsToProtocol:NSProtocolFromString( @"WebDocumentText" )] )
		{
			// This raises NOT_FOUND_ERR: DOMException 8
			NSString *string = [(<WebDocumentText>)documentView string];
			
			// We never get here.
			NSLog( @"string: %@", string );
		}

Here's the gdb backtrace:
#0  0x94830e17 in objc_exception_throw ()
#1  0x94f5bbd1 in -[NSException raise] ()
#2  0x037d48f8 in WebCore::raiseDOMException (ec=8) at /Users/Shared/data/source/WebKit/WebCore/bindings/objc/ExceptionHandlers.mm:76
#3  0x0369133b in WebCore::raiseOnDOMError (ec=8) at ExceptionHandlers.h:53
#4  0x036b1174 in -[DOMRange selectNode:] (self=0xb2d950, _cmd=0x3cbfba, refNode=0x0) at /Users/Shared/data/source/WebKit/WebKitBuild/Debug/DerivedSources/WebCore/DOMRange.mm:187
#5  0x0030f657 in -[DOMDocument(WebDOMDocumentOperationsInternal) _createRangeWithNode:] (self=0xb84b10, _cmd=0x3cbeeb, node=0x0) at /Users/Shared/data/source/WebKit/WebKit/mac/DOM/WebDOMOperations.mm:108
#6  0x0030f60a in -[DOMDocument(WebDOMDocumentOperationsInternal) _documentRange] (self=0xb84b10, _cmd=0x3cbedc) at /Users/Shared/data/source/WebKit/WebKit/mac/DOM/WebDOMOperations.mm:114
#7  0x0033a780 in -[WebHTMLView(WebHTMLViewFileInternal) _documentRange] (self=0xb63b50, _cmd=0x3cbedc) at /Users/Shared/data/source/WebKit/WebKit/mac/WebView/WebHTMLView.mm:576
#8  0x00334c88 in -[WebHTMLView(WebDocumentPrivateProtocols) string] (self=0xb63b50, _cmd=0x9488ea04) at /Users/Shared/data/source/WebKit/WebKit/mac/WebView/WebHTMLView.mm:5889
#9  0x000031f6 in -[MyDocument webView:didFinishLoadForFrame:] (self=0xb3b2f0, _cmd=0x3e01c8, sender=0xb49910, frame=0xb522e0) at /Users/Shared/data/source/MiniBrowser/MyDocument.m:245
#10 0x003b9450 in CallDelegate (implementation=0x30a2 <-[MyDocument webView:didFinishLoadForFrame:]>, self=0xb49910, delegate=0xb3b2f0, selector=0x3e01c8, object=0xb522e0) at /Users/Shared/data/source/WebKit/WebKit/mac/WebView/WebDelegateImplementationCaching.mm:263
#11 0x003b94c9 in CallFrameLoadDelegate (implementation=0x30a2 <-[MyDocument webView:didFinishLoadForFrame:]>, self=0xb49910, selector=0x3e01c8, object=0xb522e0) at /Users/Shared/data/source/WebKit/WebKit/mac/WebView/WebDelegateImplementationCaching.mm:463
#12 0x003250cd in WebFrameLoaderClient::dispatchDidFinishLoad (this=0xb52900) at /Users/Shared/data/source/WebKit/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm:617
#13 0x0381a3aa in WebCore::FrameLoader::checkLoadCompleteForThisFrame (this=0x703fc2c) at /Users/Shared/data/source/WebKit/WebCore/loader/FrameLoader.cpp:3348
#14 0x0381a516 in WebCore::FrameLoader::recursiveCheckLoadComplete (this=0x703fc2c) at /Users/Shared/data/source/WebKit/WebCore/loader/FrameLoader.cpp:3469
#15 0x0381a5bd in WebCore::FrameLoader::checkLoadComplete (this=0x703fc2c) at /Users/Shared/data/source/WebKit/WebCore/loader/FrameLoader.cpp:3480
#16 0x0381a6b1 in WebCore::FrameLoader::finishedLoading (this=0x703fc2c) at /Users/Shared/data/source/WebKit/WebCore/loader/FrameLoader.cpp:3102
#17 0x03b10eb5 in WebCore::MainResourceLoader::didFinishLoading (this=0x7040a00) at /Users/Shared/data/source/WebKit/WebCore/loader/MainResourceLoader.cpp:379
#18 0x03c73dc4 in WebCore::ResourceLoader::didFinishLoading (this=0x7040a00) at /Users/Shared/data/source/WebKit/WebCore/loader/ResourceLoader.cpp:416
#19 0x03c70b85 in -[WebCoreResourceHandleAsDelegate connectionDidFinishLoading:] (self=0xb2a3e0, _cmd=0x9489a564, connection=0xb40b70) at /Users/Shared/data/source/WebKit/WebCore/platform/network/mac/ResourceHandleMac.mm:717
#20 0x972c14a7 in -[NSURLConnection(NSURLConnectionReallyInternal) sendDidFinishLoading] ()
#21 0x972c1413 in _NSURLConnectionDidFinishLoading ()
#22 0x91458b96 in URLConnectionClient::_clientDidFinishLoading ()
#23 0x914598e0 in URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload ()
#24 0x91459b90 in URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload ()
#25 0x9145836c in URLConnectionClient::processEvents ()
#26 0x91405dbf in MultiplexerSource::perform ()
#27 0x94ee2595 in CFRunLoopRunSpecific ()
#28 0x94ee2c78 in CFRunLoopRunInMode ()
#29 0x91a8e28c in RunCurrentEventLoopInMode ()
#30 0x91a8e0a5 in ReceiveNextEventCommon ()
#31 0x91a8df19 in BlockUntilNextEventMatchingListInMode ()
#32 0x9592fd0d in _DPSNextEvent ()
#33 0x9592f5c0 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#34 0x959285fb in -[NSApplication run] ()
#35 0x958f5834 in NSApplicationMain ()
#36 0x00001c3c in main (argc=1, argv=0xbffff6d0) at /Users/Shared/data/source/MiniBrowser/main.m:45
Comment 1 Jeff Johnson 2009-06-26 16:49:18 PDT
Created attachment 31959 [details]
Sample Xcode project
Comment 2 Jeff Johnson 2009-06-26 17:19:02 PDT
I should note that I discovered the exception with Safari, which calls [(<WebDocumentText>)documentView
string] when loading the file.
Comment 3 Alexey Proskuryakov 2009-06-30 03:05:30 PDT
Confirmed with r24474 (using Safari).

An empty text document should have a complete HTML document structure, just like a non-empty one does.
Comment 4 Alexey Proskuryakov 2009-06-30 03:21:38 PDT
Confirmed with r45370, that is (copy/paste mistake).
Comment 5 Alexey Proskuryakov 2009-06-30 04:53:24 PDT
Created attachment 32052 [details]
proposed fix
Comment 6 Alexey Proskuryakov 2009-06-30 11:31:43 PDT
Committed <http://trac.webkit.org/changeset/45385>.
Comment 7 Jeff Johnson 2009-06-30 13:09:34 PDT
Confirmed as fixed in r45385. Thanks!