Changeset 286492 in webkit
- Timestamp:
- Dec 3, 2021 8:50:58 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r286491 r286492 1 2021-12-03 Alex Christensen <achristensen@webkit.org> 2 3 Add room for more bytecode in WKContentRuleList file format 4 https://bugs.webkit.org/show_bug.cgi?id=233780 5 6 Reviewed by Tim Hatcher. 7 8 For rdar://72203352 we will need more bytecode. This adds room for it without putting anything there yet. 9 As long as we are updating the version number and forcing a recompile, I'm making the string serialization 10 more like the other action serializations to be able to simplify the interpreter later. I'm also shifting 11 around a few bits in the bytecode to be more organized and reasonable. 12 13 * contentextensions/CompiledContentExtension.h: 14 * contentextensions/ContentExtensionStringSerialization.cpp: 15 (WebCore::ContentExtensions::deserializeString): 16 (WebCore::ContentExtensions::serializeString): 17 (WebCore::ContentExtensions::stringSerializedLength): 18 * contentextensions/DFABytecode.h: 19 (WebCore::ContentExtensions::smallestPossibleJumpSize): Deleted. 20 * contentextensions/DFABytecodeCompiler.cpp: 21 (WebCore::ContentExtensions::smallestPossibleJumpSize): 22 1 23 2021-12-03 Eric Carlson <eric.carlson@apple.com> 2 24 -
trunk/Source/WebCore/contentextensions/CompiledContentExtension.h
r286402 r286492 42 42 virtual Span<const uint8_t> filtersWithConditionsBytecode() const = 0; 43 43 virtual Span<const uint8_t> topURLFiltersBytecode() const = 0; 44 virtual Span<const uint8_t> frameURLFiltersBytecode() const = 0; 44 45 virtual Span<const uint8_t> serializedActions() const = 0; 45 46 virtual bool conditionsApplyOnlyToDomain() const = 0; -
trunk/Source/WebCore/contentextensions/ContentExtensionStringSerialization.cpp
r285350 r286492 33 33 String deserializeString(Span<const uint8_t> span) 34 34 { 35 const auto* actions = span.data(); 36 const auto actionsLength = span.size(); 37 auto prefixLength = sizeof(uint32_t) + sizeof(bool); 38 auto stringStartIndex = prefixLength; 39 RELEASE_ASSERT(actionsLength >= stringStartIndex); 40 uint32_t stringLength = *reinterpret_cast<const uint32_t*>(actions); 41 bool wideCharacters = actions[sizeof(uint32_t)]; 42 43 if (wideCharacters) { 44 RELEASE_ASSERT(actionsLength >= stringStartIndex + stringLength * sizeof(UChar)); 45 return String(reinterpret_cast<const UChar*>(&actions[stringStartIndex]), stringLength); 46 } 47 RELEASE_ASSERT(actionsLength >= stringStartIndex + stringLength * sizeof(LChar)); 48 return String(reinterpret_cast<const LChar*>(&actions[stringStartIndex]), stringLength); 35 auto serializedLength = *reinterpret_cast<const uint32_t*>(span.data()); 36 return String::fromUTF8(span.data() + sizeof(uint32_t), serializedLength - sizeof(uint32_t)); 49 37 } 50 38 51 39 void serializeString(Vector<uint8_t>& actions, const String& string) 52 40 { 53 // Append Selector length (4 bytes). 54 uint32_t stringLength = string.length(); 55 actions.grow(actions.size() + sizeof(uint32_t)); 56 *reinterpret_cast<uint32_t*>(&actions[actions.size() - sizeof(uint32_t)]) = stringLength; 57 bool wideCharacters = !string.is8Bit(); 58 actions.append(wideCharacters); 59 // Append Selector. 60 if (wideCharacters) { 61 uint32_t startIndex = actions.size(); 62 actions.grow(actions.size() + sizeof(UChar) * stringLength); 63 for (uint32_t i = 0; i < stringLength; ++i) 64 *reinterpret_cast<UChar*>(&actions[startIndex + i * sizeof(UChar)]) = string[i]; 65 } else { 66 for (uint32_t i = 0; i < stringLength; ++i) 67 actions.append(string[i]); 68 } 41 auto utf8 = string.utf8(); 42 uint32_t serializedLength = sizeof(uint32_t) + utf8.length(); 43 actions.reserveCapacity(actions.size() + serializedLength); 44 actions.uncheckedAppend(Span<const uint8_t> { reinterpret_cast<const uint8_t*>(&serializedLength), sizeof(serializedLength) }); 45 actions.uncheckedAppend(Span<const uint8_t> { reinterpret_cast<const uint8_t*>(utf8.data()), utf8.length() }); 69 46 } 70 47 71 48 size_t stringSerializedLength(Span<const uint8_t> span) 72 49 { 73 constexpr auto prefixLength = sizeof(uint32_t) + sizeof(bool); 74 RELEASE_ASSERT(span.size() >= prefixLength); 75 auto stringLength = *reinterpret_cast<const uint32_t*>(span.data()); 76 bool wideCharacters = span[sizeof(uint32_t)]; 77 if (wideCharacters) 78 return prefixLength + stringLength * sizeof(UChar); 79 return prefixLength + stringLength * sizeof(LChar); 50 return *reinterpret_cast<const uint32_t*>(span.data()); 80 51 } 81 52 -
trunk/Source/WebCore/contentextensions/DFABytecode.h
r286383 r286492 79 79 // The last four bits contain the instruction type. 80 80 static constexpr uint8_t DFABytecodeInstructionMask = 0x0F; 81 static constexpr uint8_t DFABytecodeJumpSizeMask = 0x F0;81 static constexpr uint8_t DFABytecodeJumpSizeMask = 0x30; 82 82 static constexpr uint8_t DFABytecodeFlagsSizeMask = 0x30; 83 83 static constexpr uint8_t DFABytecodeActionSizeMask = 0xC0; … … 88 88 // DFABytecodeFlagsSize and DFABytecodeActionSize are stored in the top four bits of the DFABytecodeInstructions that have flags and actions. 89 89 enum class DFABytecodeFlagsSize : uint8_t { 90 UInt8 = 0x 10,91 UInt16 = 0x 00, // Needs to be zero to be binary compatible with bytecode compiled with fixed-size flags.90 UInt8 = 0x00, 91 UInt16 = 0x10, 92 92 UInt24 = 0x20, 93 93 }; 94 94 enum class DFABytecodeActionSize : uint8_t { 95 UInt8 = 0x 40,96 UInt16 = 0x 80,97 UInt24 = 0x C0,98 UInt32 = 0x 00, // Needs to be zero to be binary compatible with bytecode compiled with fixed-size actions.95 UInt8 = 0x00, 96 UInt16 = 0x40, 97 UInt24 = 0x80, 98 UInt32 = 0xC0, 99 99 }; 100 100 101 101 // A DFABytecodeJumpSize is stored in the top four bits of the DFABytecodeInstructions that have a jump. 102 102 enum class DFABytecodeJumpSize : uint8_t { 103 Int8 = 0x 10,104 Int16 = 0x 20,105 Int24 = 0x 30,106 Int32 = 0x 40,103 Int8 = 0x00, 104 Int16 = 0x10, 105 Int24 = 0x20, 106 Int32 = 0x30, 107 107 }; 108 108 static constexpr int32_t UInt24Max = (1 << 24) - 1; … … 112 112 static constexpr size_t UInt24Size = 3; 113 113 114 static inline DFABytecodeJumpSize smallestPossibleJumpSize(int32_t longestPossibleJump)115 {116 if (longestPossibleJump <= std::numeric_limits<int8_t>::max() && longestPossibleJump >= std::numeric_limits<int8_t>::min())117 return DFABytecodeJumpSize::Int8;118 if (longestPossibleJump <= std::numeric_limits<int16_t>::max() && longestPossibleJump >= std::numeric_limits<int16_t>::min())119 return DFABytecodeJumpSize::Int16;120 if (longestPossibleJump <= Int24Max && longestPossibleJump >= Int24Min)121 return DFABytecodeJumpSize::Int24;122 return DFABytecodeJumpSize::Int32;123 }124 125 114 } // namespace WebCore::ContentExtensions 126 115 -
trunk/Source/WebCore/contentextensions/DFABytecodeCompiler.cpp
r286383 r286492 152 152 return m_nodeStartOffsets[destinationNodeIndex] - instructionLocation; 153 153 } 154 154 155 static DFABytecodeJumpSize smallestPossibleJumpSize(int32_t longestPossibleJump) 156 { 157 if (longestPossibleJump <= std::numeric_limits<int8_t>::max() && longestPossibleJump >= std::numeric_limits<int8_t>::min()) 158 return DFABytecodeJumpSize::Int8; 159 if (longestPossibleJump <= std::numeric_limits<int16_t>::max() && longestPossibleJump >= std::numeric_limits<int16_t>::min()) 160 return DFABytecodeJumpSize::Int16; 161 if (longestPossibleJump <= Int24Max && longestPossibleJump >= Int24Min) 162 return DFABytecodeJumpSize::Int24; 163 return DFABytecodeJumpSize::Int32; 164 } 165 155 166 void DFABytecodeCompiler::emitJump(uint32_t sourceNodeIndex, uint32_t destinationNodeIndex) 156 167 { -
trunk/Source/WebKit/ChangeLog
r286491 r286492 1 2021-12-03 Alex Christensen <achristensen@webkit.org> 2 3 Add room for more bytecode in WKContentRuleList file format 4 https://bugs.webkit.org/show_bug.cgi?id=233780 5 6 Reviewed by Tim Hatcher. 7 8 * Shared/WebCompiledContentRuleList.cpp: 9 (WebKit::WebCompiledContentRuleList::frameURLFiltersBytecode const): 10 * Shared/WebCompiledContentRuleList.h: 11 * Shared/WebCompiledContentRuleListData.cpp: 12 (WebKit::WebCompiledContentRuleListData::encode const): 13 (WebKit::WebCompiledContentRuleListData::decode): 14 * Shared/WebCompiledContentRuleListData.h: 15 (WebKit::WebCompiledContentRuleListData::WebCompiledContentRuleListData): 16 * UIProcess/API/APIContentRuleListStore.cpp: 17 (API::ContentRuleListMetaData::fileSize const): 18 (API::encodeContentRuleListMetaData): 19 (API::decodeContentRuleListMetaData): 20 (API::compiledToFile): 21 (API::createExtension): 22 (API::getContentRuleListSourceFromMappedFile): 23 * UIProcess/API/APIContentRuleListStore.h: 24 1 25 2021-12-03 Eric Carlson <eric.carlson@apple.com> 2 26 -
trunk/Source/WebKit/Shared/WebCompiledContentRuleList.cpp
r286402 r286492 47 47 bool WebCompiledContentRuleList::conditionsApplyOnlyToDomain() const 48 48 { 49 return *reinterpret_cast<const uint32_t*>(static_cast<const uint8_t*>(m_data.data->data()) + m_data.conditionsApplyOnlyToDomainOffset);49 return m_data.conditionsApplyOnlyToDomain; 50 50 } 51 51 … … 65 65 } 66 66 67 Span<const uint8_t> WebCompiledContentRuleList::frameURLFiltersBytecode() const 68 { 69 return spanWithOffsetAndLength(m_data.frameURLFiltersBytecodeOffset, m_data.frameURLFiltersBytecodeSize); 70 } 71 67 72 Span<const uint8_t> WebCompiledContentRuleList::serializedActions() const 68 73 { -
trunk/Source/WebKit/Shared/WebCompiledContentRuleList.h
r286402 r286492 47 47 Span<const uint8_t> filtersWithConditionsBytecode() const final; 48 48 Span<const uint8_t> topURLFiltersBytecode() const final; 49 Span<const uint8_t> frameURLFiltersBytecode() const final; 49 50 Span<const uint8_t> serializedActions() const final; 50 51 bool conditionsApplyOnlyToDomain() const final; -
trunk/Source/WebKit/Shared/WebCompiledContentRuleListData.cpp
r286084 r286492 50 50 encoder << SharedMemory::IPCHandle { WTFMove(handle), dataSize }; 51 51 52 encoder << conditionsApplyOnlyToDomain Offset;52 encoder << conditionsApplyOnlyToDomain; 53 53 encoder << actionsOffset; 54 54 encoder << actionsSize; … … 59 59 encoder << topURLFiltersBytecodeOffset; 60 60 encoder << topURLFiltersBytecodeSize; 61 encoder << frameURLFiltersBytecodeOffset; 62 encoder << frameURLFiltersBytecodeSize; 61 63 } 62 64 … … 75 77 return std::nullopt; 76 78 77 std::optional< unsigned> conditionsApplyOnlyToDomainOffset;78 decoder >> conditionsApplyOnlyToDomain Offset;79 if (!conditionsApplyOnlyToDomain Offset)79 std::optional<bool> conditionsApplyOnlyToDomain; 80 decoder >> conditionsApplyOnlyToDomain; 81 if (!conditionsApplyOnlyToDomain) 80 82 return std::nullopt; 81 83 82 std::optional< unsigned> actionsOffset;84 std::optional<size_t> actionsOffset; 83 85 decoder >> actionsOffset; 84 86 if (!actionsOffset) 85 87 return std::nullopt; 86 88 87 std::optional< unsigned> actionsSize;89 std::optional<size_t> actionsSize; 88 90 decoder >> actionsSize; 89 91 if (!actionsSize) 90 92 return std::nullopt; 91 93 92 std::optional< unsigned> filtersWithoutConditionsBytecodeOffset;94 std::optional<size_t> filtersWithoutConditionsBytecodeOffset; 93 95 decoder >> filtersWithoutConditionsBytecodeOffset; 94 96 if (!filtersWithoutConditionsBytecodeOffset) 95 97 return std::nullopt; 96 98 97 std::optional< unsigned> filtersWithoutConditionsBytecodeSize;99 std::optional<size_t> filtersWithoutConditionsBytecodeSize; 98 100 decoder >> filtersWithoutConditionsBytecodeSize; 99 101 if (!filtersWithoutConditionsBytecodeSize) 100 102 return std::nullopt; 101 103 102 std::optional< unsigned> filtersWithConditionsBytecodeOffset;104 std::optional<size_t> filtersWithConditionsBytecodeOffset; 103 105 decoder >> filtersWithConditionsBytecodeOffset; 104 106 if (!filtersWithConditionsBytecodeOffset) 105 107 return std::nullopt; 106 108 107 std::optional< unsigned> filtersWithConditionsBytecodeSize;109 std::optional<size_t> filtersWithConditionsBytecodeSize; 108 110 decoder >> filtersWithConditionsBytecodeSize; 109 111 if (!filtersWithConditionsBytecodeSize) 110 112 return std::nullopt; 111 113 112 std::optional< unsigned> topURLFiltersBytecodeOffset;114 std::optional<size_t> topURLFiltersBytecodeOffset; 113 115 decoder >> topURLFiltersBytecodeOffset; 114 116 if (!topURLFiltersBytecodeOffset) 115 117 return std::nullopt; 116 118 117 std::optional< unsigned> topURLFiltersBytecodeSize;119 std::optional<size_t> topURLFiltersBytecodeSize; 118 120 decoder >> topURLFiltersBytecodeSize; 119 121 if (!topURLFiltersBytecodeSize) 122 return std::nullopt; 123 124 std::optional<size_t> frameURLFiltersBytecodeOffset; 125 decoder >> frameURLFiltersBytecodeOffset; 126 if (!frameURLFiltersBytecodeOffset) 127 return std::nullopt; 128 129 std::optional<size_t> frameURLFiltersBytecodeSize; 130 decoder >> frameURLFiltersBytecodeSize; 131 if (!frameURLFiltersBytecodeSize) 120 132 return std::nullopt; 121 133 … … 123 135 WTFMove(*identifier), 124 136 data.releaseNonNull(), 125 WTFMove(*conditionsApplyOnlyToDomain Offset),137 WTFMove(*conditionsApplyOnlyToDomain), 126 138 WTFMove(*actionsOffset), 127 139 WTFMove(*actionsSize), … … 131 143 WTFMove(*filtersWithConditionsBytecodeSize), 132 144 WTFMove(*topURLFiltersBytecodeOffset), 133 WTFMove(*topURLFiltersBytecodeSize) 145 WTFMove(*topURLFiltersBytecodeSize), 146 WTFMove(*frameURLFiltersBytecodeOffset), 147 WTFMove(*frameURLFiltersBytecodeSize) 134 148 }}; 135 149 } -
trunk/Source/WebKit/Shared/WebCompiledContentRuleListData.h
r286084 r286492 42 42 class WebCompiledContentRuleListData { 43 43 public: 44 WebCompiledContentRuleListData(String&& identifier, Ref<SharedMemory>&& data, unsigned conditionsApplyOnlyToDomainOffset, unsigned actionsOffset, unsigned actionsSize, unsigned filtersWithoutConditionsBytecodeOffset, unsigned filtersWithoutConditionsBytecodeSize, unsigned filtersWithConditionsBytecodeOffset, unsigned filtersWithConditionsBytecodeSize, unsigned topURLFiltersBytecodeOffset, unsigned topURLFiltersBytecodeSize)44 WebCompiledContentRuleListData(String&& identifier, Ref<SharedMemory>&& data, bool conditionsApplyOnlyToDomain, size_t actionsOffset, size_t actionsSize, size_t filtersWithoutConditionsBytecodeOffset, size_t filtersWithoutConditionsBytecodeSize, size_t filtersWithConditionsBytecodeOffset, size_t filtersWithConditionsBytecodeSize, size_t topURLFiltersBytecodeOffset, size_t topURLFiltersBytecodeSize, size_t frameURLFiltersBytecodeOffset, size_t frameURLFiltersBytecodeSize) 45 45 : identifier(WTFMove(identifier)) 46 46 , data(WTFMove(data)) 47 , conditionsApplyOnlyToDomain Offset(conditionsApplyOnlyToDomainOffset)47 , conditionsApplyOnlyToDomain(conditionsApplyOnlyToDomain) 48 48 , actionsOffset(actionsOffset) 49 49 , actionsSize(actionsSize) … … 54 54 , topURLFiltersBytecodeOffset(topURLFiltersBytecodeOffset) 55 55 , topURLFiltersBytecodeSize(topURLFiltersBytecodeSize) 56 , frameURLFiltersBytecodeOffset(frameURLFiltersBytecodeOffset) 57 , frameURLFiltersBytecodeSize(frameURLFiltersBytecodeSize) 56 58 { 57 59 } … … 62 64 String identifier; 63 65 Ref<SharedMemory> data; 64 unsigned conditionsApplyOnlyToDomainOffset { 0 }; 65 unsigned actionsOffset { 0 }; 66 unsigned actionsSize { 0 }; 67 unsigned filtersWithoutConditionsBytecodeOffset { 0 }; 68 unsigned filtersWithoutConditionsBytecodeSize { 0 }; 69 unsigned filtersWithConditionsBytecodeOffset { 0 }; 70 unsigned filtersWithConditionsBytecodeSize { 0 }; 71 unsigned topURLFiltersBytecodeOffset { 0 }; 72 unsigned topURLFiltersBytecodeSize { 0 }; 66 bool conditionsApplyOnlyToDomain { 0 }; 67 size_t actionsOffset { 0 }; 68 size_t actionsSize { 0 }; 69 size_t filtersWithoutConditionsBytecodeOffset { 0 }; 70 size_t filtersWithoutConditionsBytecodeSize { 0 }; 71 size_t filtersWithConditionsBytecodeOffset { 0 }; 72 size_t filtersWithConditionsBytecodeSize { 0 }; 73 size_t topURLFiltersBytecodeOffset { 0 }; 74 size_t topURLFiltersBytecodeSize { 0 }; 75 size_t frameURLFiltersBytecodeOffset { 0 }; 76 size_t frameURLFiltersBytecodeSize { 0 }; 73 77 }; 74 78 -
trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp
r286084 r286492 97 97 // The size and offset of the densely packed bytes in the file, not sizeof and offsetof, which would 98 98 // represent the size and offset of the structure in memory, possibly with compiler-added padding. 99 const size_t ContentRuleListFileHeaderSize = 2 * sizeof(uint32_t) + 5 * sizeof(uint64_t); 100 const size_t ConditionsApplyOnlyToDomainOffset = sizeof(uint32_t) + 5 * sizeof(uint64_t); 99 const size_t CurrentVersionFileHeaderSize = 2 * sizeof(uint32_t) + 7 * sizeof(uint64_t); 100 101 static size_t headerSize(uint32_t version) 102 { 103 if (version < 12) 104 return 2 * sizeof(uint32_t) + 5 * sizeof(uint64_t); 105 return CurrentVersionFileHeaderSize; 106 } 101 107 102 108 struct ContentRuleListMetaData { … … 108 114 uint64_t conditionedFiltersBytecodeSize { 0 }; 109 115 uint32_t conditionsApplyOnlyToDomain { false }; 116 uint64_t frameURLFiltersBytecodeSize { 0 }; 117 uint64_t unused { 0 }; // Additional space on disk reserved so we can add something without incrementing the version number. 110 118 111 119 size_t fileSize() const 112 120 { 113 return ContentRuleListFileHeaderSize121 return headerSize(version) 114 122 + sourceSize 115 123 + actionsSize 116 124 + filtersWithoutConditionsBytecodeSize 117 125 + filtersWithConditionsBytecodeSize 118 + conditionedFiltersBytecodeSize; 126 + conditionedFiltersBytecodeSize 127 + frameURLFiltersBytecodeSize; 119 128 } 120 129 }; … … 131 140 encoder << metaData.conditionedFiltersBytecodeSize; 132 141 encoder << metaData.conditionsApplyOnlyToDomain; 133 134 ASSERT(encoder.bufferSize() == ContentRuleListFileHeaderSize); 142 encoder << metaData.frameURLFiltersBytecodeSize; 143 encoder << metaData.unused; 144 145 ASSERT(encoder.bufferSize() == CurrentVersionFileHeaderSize); 135 146 return WebKit::NetworkCache::Data(encoder.buffer(), encoder.bufferSize()); 136 147 } … … 146 157 } 147 158 148 template<typename T> 149 static std::optional<ContentRuleListMetaData> decodeContentRuleListMetaData(const T& fileData) 150 { 151 bool success = false; 159 static std::optional<ContentRuleListMetaData> decodeContentRuleListMetaData(const WebKit::NetworkCache::Data& fileData) 160 { 152 161 ContentRuleListMetaData metaData; 153 getData(fileData, [&metaData, &success, &fileData](Span<const uint8_t> span) { 154 // The file data should be mapped into one continuous memory segment so the size 155 // passed to the applier should always equal the data size. 156 if (span.size() != fileData.size()) 157 return false; 158 159 WTF::Persistence::Decoder decoder(span); 160 161 std::optional<uint32_t> version; 162 decoder >> version; 163 if (!version) 164 return false; 165 metaData.version = WTFMove(*version); 166 167 std::optional<uint64_t> sourceSize; 168 decoder >> sourceSize; 169 if (!sourceSize) 170 return false; 171 metaData.sourceSize = WTFMove(*sourceSize); 172 173 std::optional<uint64_t> actionsSize; 174 decoder >> actionsSize; 175 if (!actionsSize) 176 return false; 177 metaData.actionsSize = WTFMove(*actionsSize); 178 179 std::optional<uint64_t> filtersWithoutConditionsBytecodeSize; 180 decoder >> filtersWithoutConditionsBytecodeSize; 181 if (!filtersWithoutConditionsBytecodeSize) 182 return false; 183 metaData.filtersWithoutConditionsBytecodeSize = WTFMove(*filtersWithoutConditionsBytecodeSize); 184 185 std::optional<uint64_t> filtersWithConditionsBytecodeSize; 186 decoder >> filtersWithConditionsBytecodeSize; 187 if (!filtersWithConditionsBytecodeSize) 188 return false; 189 metaData.filtersWithConditionsBytecodeSize = WTFMove(*filtersWithConditionsBytecodeSize); 190 191 std::optional<uint64_t> conditionedFiltersBytecodeSize; 192 decoder >> conditionedFiltersBytecodeSize; 193 if (!conditionedFiltersBytecodeSize) 194 return false; 195 metaData.conditionedFiltersBytecodeSize = WTFMove(*conditionedFiltersBytecodeSize); 196 197 std::optional<uint32_t> conditionsApplyOnlyToDomain; 198 decoder >> conditionsApplyOnlyToDomain; 199 if (!conditionsApplyOnlyToDomain) 200 return false; 201 metaData.conditionsApplyOnlyToDomain = WTFMove(*conditionsApplyOnlyToDomain); 202 203 success = true; 204 return false; 205 }); 206 if (!success) 207 return std::nullopt; 162 auto span = fileData.span(); 163 164 WTF::Persistence::Decoder decoder(span); 165 166 std::optional<uint32_t> version; 167 decoder >> version; 168 if (!version) 169 return std::nullopt; 170 metaData.version = WTFMove(*version); 171 172 std::optional<uint64_t> sourceSize; 173 decoder >> sourceSize; 174 if (!sourceSize) 175 return std::nullopt; 176 metaData.sourceSize = WTFMove(*sourceSize); 177 178 std::optional<uint64_t> actionsSize; 179 decoder >> actionsSize; 180 if (!actionsSize) 181 return std::nullopt; 182 metaData.actionsSize = WTFMove(*actionsSize); 183 184 std::optional<uint64_t> filtersWithoutConditionsBytecodeSize; 185 decoder >> filtersWithoutConditionsBytecodeSize; 186 if (!filtersWithoutConditionsBytecodeSize) 187 return std::nullopt; 188 metaData.filtersWithoutConditionsBytecodeSize = WTFMove(*filtersWithoutConditionsBytecodeSize); 189 190 std::optional<uint64_t> filtersWithConditionsBytecodeSize; 191 decoder >> filtersWithConditionsBytecodeSize; 192 if (!filtersWithConditionsBytecodeSize) 193 return std::nullopt; 194 metaData.filtersWithConditionsBytecodeSize = WTFMove(*filtersWithConditionsBytecodeSize); 195 196 std::optional<uint64_t> conditionedFiltersBytecodeSize; 197 decoder >> conditionedFiltersBytecodeSize; 198 if (!conditionedFiltersBytecodeSize) 199 return std::nullopt; 200 metaData.conditionedFiltersBytecodeSize = WTFMove(*conditionedFiltersBytecodeSize); 201 202 std::optional<uint32_t> conditionsApplyOnlyToDomain; 203 decoder >> conditionsApplyOnlyToDomain; 204 if (!conditionsApplyOnlyToDomain) 205 return std::nullopt; 206 metaData.conditionsApplyOnlyToDomain = WTFMove(*conditionsApplyOnlyToDomain); 207 208 if (metaData.version < 12) 209 return metaData; 210 211 std::optional<uint64_t> frameURLFiltersBytecodeSize; 212 decoder >> frameURLFiltersBytecodeSize; 213 if (!frameURLFiltersBytecodeSize) 214 return std::nullopt; 215 metaData.frameURLFiltersBytecodeSize = WTFMove(*frameURLFiltersBytecodeSize); 216 217 std::optional<uint64_t> unused; 218 decoder >> unused; 219 if (!unused) 220 return std::nullopt; 221 metaData.unused = 0; 222 208 223 return metaData; 209 224 } … … 360 375 } 361 376 362 char invalidHeader[C ontentRuleListFileHeaderSize];377 char invalidHeader[CurrentVersionFileHeaderSize]; 363 378 memset(invalidHeader, 0xFF, sizeof(invalidHeader)); 364 379 // This header will be rewritten in CompilationClient::finalize. … … 411 426 RELEASE_ASSERT(sharedMemory); 412 427 413 const size_t headerAndSourceSize = ContentRuleListFileHeaderSize+ data.metaData.sourceSize;428 const size_t headerAndSourceSize = headerSize(data.metaData.version) + data.metaData.sourceSize; 414 429 auto compiledContentRuleListData = WebKit::WebCompiledContentRuleListData( 415 430 WTF::String(identifier), 416 431 sharedMemory.releaseNonNull(), 417 ConditionsApplyOnlyToDomainOffset,432 data.metaData.conditionsApplyOnlyToDomain, 418 433 headerAndSourceSize, 419 434 data.metaData.actionsSize, … … 429 444 + data.metaData.filtersWithoutConditionsBytecodeSize 430 445 + data.metaData.filtersWithConditionsBytecodeSize, 431 data.metaData.conditionedFiltersBytecodeSize 446 data.metaData.conditionedFiltersBytecodeSize, 447 headerAndSourceSize 448 + data.metaData.actionsSize 449 + data.metaData.filtersWithoutConditionsBytecodeSize 450 + data.metaData.filtersWithConditionsBytecodeSize 451 + data.metaData.conditionedFiltersBytecodeSize, 452 data.metaData.frameURLFiltersBytecodeSize 432 453 ); 433 454 auto compiledContentRuleList = WebKit::WebCompiledContentRuleList::create(WTFMove(compiledContentRuleListData)); … … 443 464 case 10: 444 465 case 11: 466 case 12: 445 467 if (!mappedData.metaData.sourceSize) 446 468 return { }; 447 bool is8Bit = mappedData.data.data()[ContentRuleListFileHeaderSize]; 448 size_t start = ContentRuleListFileHeaderSize + sizeof(bool); 469 470 auto headerSizeBytes = headerSize(mappedData.metaData.version); 471 bool is8Bit = mappedData.data.data()[headerSizeBytes]; 472 size_t start = headerSizeBytes + sizeof(bool); 449 473 size_t length = mappedData.metaData.sourceSize - sizeof(bool); 450 474 if (is8Bit) -
trunk/Source/WebKit/UIProcess/API/APIContentRuleListStore.h
r286041 r286492 55 55 // This should be incremented every time a functional change is made to the bytecode, file format, etc. 56 56 // to prevent crashing while loading old data. 57 // Also update ContentRuleListStore::getContentRuleListSource to be able to find the original JSON57 // Also update getContentRuleListSourceFromMappedFile to be able to find the original JSON 58 58 // source from old versions. 59 // Update getContentRuleListSourceFromMappedFile with this. 60 static constexpr uint32_t CurrentContentRuleListFileVersion = 11; 59 static constexpr uint32_t CurrentContentRuleListFileVersion = 12; 61 60 62 61 static ContentRuleListStore& defaultStore(); -
trunk/Tools/ChangeLog
r286488 r286492 1 2021-12-03 Alex Christensen <achristensen@webkit.org> 2 3 Add room for more bytecode in WKContentRuleList file format 4 https://bugs.webkit.org/show_bug.cgi?id=233780 5 6 Reviewed by Tim Hatcher. 7 8 * TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp: 9 1 10 2021-12-03 Youenn Fablet <youenn@apple.com> 2 11 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/ContentExtensions.cpp
r286402 r286492 67 67 Vector<ContentExtensions::DFABytecode> filtersWithConditions; 68 68 Vector<ContentExtensions::DFABytecode> topURLFilters; 69 Vector<ContentExtensions::DFABytecode> frameURLFilters; 69 70 bool conditionsApplyOnlyToDomain { false }; 70 71 }; … … 148 149 Span<const uint8_t> filtersWithConditionsBytecode() const final { return { m_data.filtersWithConditions.data(), m_data.filtersWithConditions.size() }; } 149 150 Span<const uint8_t> topURLFiltersBytecode() const final { return { m_data.topURLFilters.data(), m_data.topURLFilters.size() }; } 151 Span<const uint8_t> frameURLFiltersBytecode() const final { return { m_data.frameURLFilters.data(), m_data.frameURLFilters.size() }; } 150 152 bool conditionsApplyOnlyToDomain() const final { return m_data.conditionsApplyOnlyToDomain; } 151 153 … … 967 969 ASSERT_EQ(sequenceInstances(data.actions, "GGG"), 1); 968 970 969 ASSERT_EQ(data.actions.size(), 7 8u);971 ASSERT_EQ(data.actions.size(), 72u); 970 972 ASSERT_EQ(data.filtersWithoutConditions.size(), 288u); 971 973 ASSERT_EQ(data.filtersWithConditions.size(), 5u); -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentExtensionStore.mm
r286383 r286492 253 253 NSData *data = [NSData dataWithContentsOfURL:[tempDir URLByAppendingPathComponent:fileName]]; 254 254 EXPECT_NOT_NULL(data); 255 EXPECT_EQ(data.length, 2 25u);255 EXPECT_EQ(data.length, 241u); 256 256 257 257 __block bool doneCheckingSource = false;
Note: See TracChangeset
for help on using the changeset viewer.