Title: [203008] trunk/Source/WebCore
- Revision
- 203008
- Author
- [email protected]
- Date
- 2016-07-08 16:49:15 -0700 (Fri, 08 Jul 2016)
Log Message
Crash in layout test /media/video-buffered-range-contains-currentTime.html
https://bugs.webkit.org/show_bug.cgi?id=159109
<rdar://problem/26535750>
Reviewed by Alex Christensen.
Protect against _dataTasks being mutated and accessed on multiple simultaneous threads with a Lock.
* platform/network/cocoa/WebCoreNSURLSession.h:
* platform/network/cocoa/WebCoreNSURLSession.mm:
(-[WebCoreNSURLSession dealloc]):
(-[WebCoreNSURLSession taskCompleted:]):
(-[WebCoreNSURLSession finishTasksAndInvalidate]):
(-[WebCoreNSURLSession invalidateAndCancel]):
(-[WebCoreNSURLSession getTasksWithCompletionHandler:]):
(-[WebCoreNSURLSession getAllTasksWithCompletionHandler:]):
(-[WebCoreNSURLSession dataTaskWithRequest:]):
(-[WebCoreNSURLSession dataTaskWithURL:]):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (203007 => 203008)
--- trunk/Source/WebCore/ChangeLog 2016-07-08 23:38:04 UTC (rev 203007)
+++ trunk/Source/WebCore/ChangeLog 2016-07-08 23:49:15 UTC (rev 203008)
@@ -1,3 +1,24 @@
+2016-07-08 Jer Noble <[email protected]>
+
+ Crash in layout test /media/video-buffered-range-contains-currentTime.html
+ https://bugs.webkit.org/show_bug.cgi?id=159109
+ <rdar://problem/26535750>
+
+ Reviewed by Alex Christensen.
+
+ Protect against _dataTasks being mutated and accessed on multiple simultaneous threads with a Lock.
+
+ * platform/network/cocoa/WebCoreNSURLSession.h:
+ * platform/network/cocoa/WebCoreNSURLSession.mm:
+ (-[WebCoreNSURLSession dealloc]):
+ (-[WebCoreNSURLSession taskCompleted:]):
+ (-[WebCoreNSURLSession finishTasksAndInvalidate]):
+ (-[WebCoreNSURLSession invalidateAndCancel]):
+ (-[WebCoreNSURLSession getTasksWithCompletionHandler:]):
+ (-[WebCoreNSURLSession getAllTasksWithCompletionHandler:]):
+ (-[WebCoreNSURLSession dataTaskWithRequest:]):
+ (-[WebCoreNSURLSession dataTaskWithURL:]):
+
2016-07-08 Jeremy Jones <[email protected]>
Prevent fullscreen video dimension state from being reset after configuring.
Modified: trunk/Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.h (203007 => 203008)
--- trunk/Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.h 2016-07-08 23:38:04 UTC (rev 203007)
+++ trunk/Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.h 2016-07-08 23:49:15 UTC (rev 203008)
@@ -30,6 +30,7 @@
#import <Foundation/NSURLSession.h>
#import <wtf/HashSet.h>
+#import <wtf/Lock.h>
#import <wtf/OSObjectPtr.h>
#import <wtf/RefPtr.h>
#import <wtf/RetainPtr.h>
@@ -63,6 +64,7 @@
RetainPtr<NSOperationQueue> _queue;
NSString *_sessionDescription;
HashSet<RetainPtr<WebCoreNSURLSessionDataTask>> _dataTasks;
+ Lock _dataTasksLock;
BOOL _invalidated;
BOOL _hasSingleSecurityOrigin;
NSUInteger _nextTaskIdentifier;
Modified: trunk/Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.mm (203007 => 203008)
--- trunk/Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.mm 2016-07-08 23:38:04 UTC (rev 203007)
+++ trunk/Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.mm 2016-07-08 23:49:15 UTC (rev 203008)
@@ -92,8 +92,11 @@
- (void)dealloc
{
- for (auto& task : _dataTasks)
- task.get().session = nil;
+ {
+ Locker<Lock> locker(_dataTasksLock);
+ for (auto& task : _dataTasks)
+ task.get().session = nil;
+ }
callOnMainThread([loader = WTFMove(_loader)] {
});
@@ -110,12 +113,17 @@
- (void)taskCompleted:(WebCoreNSURLSessionDataTask *)task
{
- ASSERT(_dataTasks.contains(task));
task.session = nil;
- _dataTasks.remove(task);
- if (!_dataTasks.isEmpty() || !_invalidated)
- return;
+ {
+ Locker<Lock> locker(_dataTasksLock);
+
+ ASSERT(_dataTasks.contains(task));
+ _dataTasks.remove(task);
+ if (!_dataTasks.isEmpty() || !_invalidated)
+ return;
+ }
+
RetainPtr<WebCoreNSURLSession> strongSelf { self };
[self addDelegateOperation:[strongSelf] {
if ([strongSelf.get().delegate respondsToSelector:@selector(URLSession:didBecomeInvalidWithError:)])
@@ -195,8 +203,11 @@
- (void)finishTasksAndInvalidate
{
_invalidated = YES;
- if (!_dataTasks.isEmpty())
- return;
+ {
+ Locker<Lock> locker(_dataTasksLock);
+ if (!_dataTasks.isEmpty())
+ return;
+ }
RetainPtr<WebCoreNSURLSession> strongSelf { self };
[self addDelegateOperation:[strongSelf] {
@@ -207,7 +218,13 @@
- (void)invalidateAndCancel
{
- for (auto& task : _dataTasks)
+ Vector<RetainPtr<WebCoreNSURLSessionDataTask>> tasksCopy;
+ {
+ Locker<Lock> locker(_dataTasksLock);
+ copyToVector(_dataTasks, tasksCopy);
+ }
+
+ for (auto& task : tasksCopy)
[task cancel];
[self finishTasksAndInvalidate];
@@ -227,9 +244,13 @@
- (void)getTasksWithCompletionHandler:(void (^)(NSArray<NSURLSessionDataTask *> *dataTasks, NSArray<NSURLSessionUploadTask *> *uploadTasks, NSArray<NSURLSessionDownloadTask *> *downloadTasks))completionHandler
{
- NSMutableArray *array = [NSMutableArray arrayWithCapacity:_dataTasks.size()];
- for (auto& task : _dataTasks)
- [array addObject:task.get()];
+ NSMutableArray *array = nullptr;
+ {
+ Locker<Lock> locker(_dataTasksLock);
+ array = [NSMutableArray arrayWithCapacity:_dataTasks.size()];
+ for (auto& task : _dataTasks)
+ [array addObject:task.get()];
+ }
[self addDelegateOperation:^{
completionHandler(array, nil, nil);
}];
@@ -237,9 +258,13 @@
- (void)getAllTasksWithCompletionHandler:(void (^)(NSArray<__kindof NSURLSessionTask *> *tasks))completionHandler
{
- NSMutableArray *array = [NSMutableArray arrayWithCapacity:_dataTasks.size()];
- for (auto& task : _dataTasks)
- [array addObject:task.get()];
+ NSMutableArray *array = nullptr;
+ {
+ Locker<Lock> locker(_dataTasksLock);
+ array = [NSMutableArray arrayWithCapacity:_dataTasks.size()];
+ for (auto& task : _dataTasks)
+ [array addObject:task.get()];
+ }
[self addDelegateOperation:^{
completionHandler(array);
}];
@@ -253,7 +278,10 @@
[self updateHasSingleSecurityOrigin:SecurityOrigin::create([request URL])];
WebCoreNSURLSessionDataTask *task = [[WebCoreNSURLSessionDataTask alloc] initWithSession:self identifier:_nextTaskIdentifier++ request:request];
- _dataTasks.add(task);
+ {
+ Locker<Lock> locker(_dataTasksLock);
+ _dataTasks.add(task);
+ }
return (NSURLSessionDataTask *)[task autorelease];
}
@@ -265,7 +293,10 @@
[self updateHasSingleSecurityOrigin:SecurityOrigin::create(url)];
WebCoreNSURLSessionDataTask *task = [[WebCoreNSURLSessionDataTask alloc] initWithSession:self identifier:_nextTaskIdentifier++ URL:url];
- _dataTasks.add(task);
+ {
+ Locker<Lock> locker(_dataTasksLock);
+ _dataTasks.add(task);
+ }
return (NSURLSessionDataTask *)[task autorelease];
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes