Title: [290850] trunk
Revision
290850
Author
[email protected]
Date
2022-03-04 15:08:19 -0800 (Fri, 04 Mar 2022)

Log Message

[iOS] Books ASSERTs upon opening a book with a debug build of WebKit
https://bugs.webkit.org/show_bug.cgi?id=237445
<rdar://problem/89776531>

Reviewed by Alex Christensen.

Source/WebCore:

* platform/sql/SQLiteDatabase.cpp:
(WebCore::SQLiteDatabase::open):

Source/WebKit:

* NetworkProcess/cache/NetworkCacheBlobStorage.cpp:
(WebKit::NetworkCache::BlobStorage::add):
* UIProcess/API/APIContentRuleListStore.cpp:
(API::openAndMapContentRuleList):
(API::compiledToFile):

Source/WTF:

makeSafeToUseMemoryMapForPath() runs an ASSERT() that it was successful.
However, it's not always successful, so this ASSERT() was getting hit when
trying to open a book in Books. So, this patch makes the function return a
bool to indicate success, and updates callers to do something sensible if
it failed.

Test: FileSystemTest.makeSafeToUseMemoryMapForPath

* wtf/FileSystem.cpp:
(WTF::FileSystemImpl::makeSafeToUseMemoryMapForPath):
(WTF::FileSystemImpl::mapToFile):
* wtf/FileSystem.h:
* wtf/cocoa/FileSystemCocoa.mm:
(WTF::FileSystemImpl::makeSafeToUseMemoryMapForPath):

Tools:

* TestWebKitAPI/Tests/WTF/FileSystem.cpp:
(TestWebKitAPI::TEST_F):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (290849 => 290850)


--- trunk/Source/WTF/ChangeLog	2022-03-04 22:57:42 UTC (rev 290849)
+++ trunk/Source/WTF/ChangeLog	2022-03-04 23:08:19 UTC (rev 290850)
@@ -1,3 +1,26 @@
+2022-03-04  Myles C. Maxfield  <[email protected]>
+
+        [iOS] Books ASSERTs upon opening a book with a debug build of WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=237445
+        <rdar://problem/89776531>
+
+        Reviewed by Alex Christensen.
+
+        makeSafeToUseMemoryMapForPath() runs an ASSERT() that it was successful.
+        However, it's not always successful, so this ASSERT() was getting hit when
+        trying to open a book in Books. So, this patch makes the function return a
+        bool to indicate success, and updates callers to do something sensible if
+        it failed.
+
+        Test: FileSystemTest.makeSafeToUseMemoryMapForPath
+
+        * wtf/FileSystem.cpp:
+        (WTF::FileSystemImpl::makeSafeToUseMemoryMapForPath):
+        (WTF::FileSystemImpl::mapToFile):
+        * wtf/FileSystem.h:
+        * wtf/cocoa/FileSystemCocoa.mm:
+        (WTF::FileSystemImpl::makeSafeToUseMemoryMapForPath):
+
 2022-03-04  Chris Dumez  <[email protected]>
 
         URL's isolatedCopy() optimization when called on a r-value reference doesn't work

Modified: trunk/Source/WTF/wtf/FileSystem.cpp (290849 => 290850)


--- trunk/Source/WTF/wtf/FileSystem.cpp	2022-03-04 22:57:42 UTC (rev 290849)
+++ trunk/Source/WTF/wtf/FileSystem.cpp	2022-03-04 23:08:19 UTC (rev 290850)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2022 Apple Inc. All rights reserved.
  * Copyright (C) 2015 Canon Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -414,8 +414,9 @@
     return true;
 }
 
-void makeSafeToUseMemoryMapForPath(const String&)
+bool makeSafeToUseMemoryMapForPath(const String&)
 {
+    return true;
 }
 #endif
 
@@ -442,7 +443,11 @@
         return { };
     }
 
-    FileSystem::makeSafeToUseMemoryMapForPath(path);
+    if (!FileSystem::makeSafeToUseMemoryMapForPath(path)) {
+        FileSystem::closeFile(handle);
+        return { };
+    }
+
     bool success;
     FileSystem::MappedFileData mappedFile(handle, FileSystem::FileOpenMode::ReadWrite, FileSystem::MappedFileMode::Shared, success);
     if (!success) {

Modified: trunk/Source/WTF/wtf/FileSystem.h (290849 => 290850)


--- trunk/Source/WTF/wtf/FileSystem.h	2022-03-04 22:57:42 UTC (rev 290849)
+++ trunk/Source/WTF/wtf/FileSystem.h	2022-03-04 23:08:19 UTC (rev 290850)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2022 Apple Inc. All rights reserved.
  * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
  * Copyright (C) 2015 Canon Inc. All rights reserved.
  *
@@ -214,7 +214,7 @@
 WTF_EXPORT_PRIVATE String realPath(const String&);
 
 WTF_EXPORT_PRIVATE bool isSafeToUseMemoryMapForPath(const String&);
-WTF_EXPORT_PRIVATE void makeSafeToUseMemoryMapForPath(const String&);
+WTF_EXPORT_PRIVATE WARN_UNUSED_RETURN bool makeSafeToUseMemoryMapForPath(const String&);
 
 class MappedFileData {
     WTF_MAKE_FAST_ALLOCATED;

Modified: trunk/Source/WTF/wtf/cocoa/FileSystemCocoa.mm (290849 => 290850)


--- trunk/Source/WTF/wtf/cocoa/FileSystemCocoa.mm	2022-03-04 22:57:42 UTC (rev 290849)
+++ trunk/Source/WTF/wtf/cocoa/FileSystemCocoa.mm	2022-03-04 23:08:19 UTC (rev 290850)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2007-2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -210,15 +210,18 @@
     return true;
 }
 
-void makeSafeToUseMemoryMapForPath(const String& path)
+bool makeSafeToUseMemoryMapForPath(const String& path)
 {
     if (isSafeToUseMemoryMapForPath(path))
-        return;
+        return true;
     
     NSError *error = nil;
     BOOL success = [[NSFileManager defaultManager] setAttributes:@{ NSFileProtectionKey: NSFileProtectionCompleteUnlessOpen } ofItemAtPath:path error:&error];
-    ASSERT(!error);
-    ASSERT_UNUSED(success, success);
+    if (error || !success) {
+        WTFLogAlways("makeSafeToUseMemoryMapForPath(%s) failed with error %@", path.utf8().data(), error);
+        return false;
+    }
+    return true;
 }
 #endif
 

Modified: trunk/Source/WebCore/ChangeLog (290849 => 290850)


--- trunk/Source/WebCore/ChangeLog	2022-03-04 22:57:42 UTC (rev 290849)
+++ trunk/Source/WebCore/ChangeLog	2022-03-04 23:08:19 UTC (rev 290850)
@@ -1,3 +1,14 @@
+2022-03-04  Myles C. Maxfield  <[email protected]>
+
+        [iOS] Books ASSERTs upon opening a book with a debug build of WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=237445
+        <rdar://problem/89776531>
+
+        Reviewed by Alex Christensen.
+
+        * platform/sql/SQLiteDatabase.cpp:
+        (WebCore::SQLiteDatabase::open):
+
 2022-03-04  Chris Dumez  <[email protected]>
 
         Home link on weather.gov is not working

Modified: trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp (290849 => 290850)


--- trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp	2022-03-04 22:57:42 UTC (rev 290849)
+++ trunk/Source/WebCore/platform/sql/SQLiteDatabase.cpp	2022-03-04 23:08:19 UTC (rev 290850)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2021 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2022 Apple Inc. All rights reserved.
  * Copyright (C) 2007 Justin Haygood ([email protected])
  *
  * Redistribution and use in source and binary forms, with or without
@@ -163,7 +163,8 @@
         auto shmFileName = makeString(filename, "-shm"_s);
         if (FileSystem::fileExists(shmFileName) && !FileSystem::isSafeToUseMemoryMapForPath(shmFileName)) {
             RELEASE_LOG_FAULT(SQLDatabase, "Opened an SQLite database with a Class A -shm file. This may trigger a crash when the user locks the device. (%s)", shmFileName.latin1().data());
-            FileSystem::makeSafeToUseMemoryMapForPath(shmFileName);
+            if (!FileSystem::makeSafeToUseMemoryMapForPath(shmFileName))
+                return false;
         }
     }
 

Modified: trunk/Source/WebKit/ChangeLog (290849 => 290850)


--- trunk/Source/WebKit/ChangeLog	2022-03-04 22:57:42 UTC (rev 290849)
+++ trunk/Source/WebKit/ChangeLog	2022-03-04 23:08:19 UTC (rev 290850)
@@ -1,3 +1,17 @@
+2022-03-04  Myles C. Maxfield  <[email protected]>
+
+        [iOS] Books ASSERTs upon opening a book with a debug build of WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=237445
+        <rdar://problem/89776531>
+
+        Reviewed by Alex Christensen.
+
+        * NetworkProcess/cache/NetworkCacheBlobStorage.cpp:
+        (WebKit::NetworkCache::BlobStorage::add):
+        * UIProcess/API/APIContentRuleListStore.cpp:
+        (API::openAndMapContentRuleList):
+        (API::compiledToFile):
+
 2022-03-04  Chris Dumez  <[email protected]>
 
         Home link on weather.gov is not working

Modified: trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheBlobStorage.cpp (290849 => 290850)


--- trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheBlobStorage.cpp	2022-03-04 22:57:42 UTC (rev 290849)
+++ trunk/Source/WebKit/NetworkProcess/cache/NetworkCacheBlobStorage.cpp	2022-03-04 23:08:19 UTC (rev 290850)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -96,12 +96,13 @@
 
     bool blobExists = FileSystem::fileExists(blobPath);
     if (blobExists) {
-        FileSystem::makeSafeToUseMemoryMapForPath(blobPath);
-        auto existingData = mapFile(blobPath);
-        if (bytesEqual(existingData, data)) {
-            if (!FileSystem::hardLink(blobPath, path))
-                WTFLogAlways("Failed to create hard link from %s to %s", blobPath.utf8().data(), path.utf8().data());
-            return { existingData, hash };
+        if (FileSystem::makeSafeToUseMemoryMapForPath(blobPath)) {
+            auto existingData = mapFile(blobPath);
+            if (bytesEqual(existingData, data)) {
+                if (!FileSystem::hardLink(blobPath, path))
+                    WTFLogAlways("Failed to create hard link from %s to %s", blobPath.utf8().data(), path.utf8().data());
+                return { existingData, hash };
+            }
         }
         FileSystem::deleteFile(blobPath);
     }

Modified: trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp (290849 => 290850)


--- trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp	2022-03-04 22:57:42 UTC (rev 290849)
+++ trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp	2022-03-04 23:08:19 UTC (rev 290850)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -229,7 +229,8 @@
 
 static std::optional<MappedData> openAndMapContentRuleList(const WTF::String& path)
 {
-    FileSystem::makeSafeToUseMemoryMapForPath(path);
+    if (!FileSystem::makeSafeToUseMemoryMapForPath(path))
+        return std::nullopt;
     WebKit::NetworkCache::Data fileData = mapFile(fileSystemRepresentation(path).data());
     if (fileData.isNull())
         return std::nullopt;
@@ -408,7 +409,8 @@
         return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
     }
     
-    FileSystem::makeSafeToUseMemoryMapForPath(finalFilePath);
+    if (!FileSystem::makeSafeToUseMemoryMapForPath(finalFilePath))
+        return makeUnexpected(ContentRuleListStore::Error::CompileFailed);
     
     return {{ WTFMove(metaData), WTFMove(mappedData) }};
 }

Modified: trunk/Tools/ChangeLog (290849 => 290850)


--- trunk/Tools/ChangeLog	2022-03-04 22:57:42 UTC (rev 290849)
+++ trunk/Tools/ChangeLog	2022-03-04 23:08:19 UTC (rev 290850)
@@ -1,3 +1,14 @@
+2022-03-04  Myles C. Maxfield  <[email protected]>
+
+        [iOS] Books ASSERTs upon opening a book with a debug build of WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=237445
+        <rdar://problem/89776531>
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/Tests/WTF/FileSystem.cpp:
+        (TestWebKitAPI::TEST_F):
+
 2022-03-04  Chris Dumez  <[email protected]>
 
         URL's isolatedCopy() optimization when called on a r-value reference doesn't work

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp (290849 => 290850)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp	2022-03-04 22:57:42 UTC (rev 290849)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/FileSystem.cpp	2022-03-04 23:08:19 UTC (rev 290850)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2015 Canon Inc. All rights reserved.
- * Copyright (C) 2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2017-2022 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -832,4 +832,16 @@
     EXPECT_STREQ(contents.utf8().data(), FileSystemTestData);
 }
 
+TEST_F(FileSystemTest, makeSafeToUseMemoryMapForPath)
+{
+    EXPECT_TRUE(FileSystem::makeSafeToUseMemoryMapForPath(tempFilePath()));
+    auto result = FileSystem::makeSafeToUseMemoryMapForPath(String("Thisisnotarealfile", String::ConstructFromLiteral));
+#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
+    // NSFileProtectionKey only actually means anything on-device.
+    EXPECT_FALSE(result);
+#else
+    EXPECT_TRUE(result);
+#endif
+}
+
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to