Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: third_party/WebKit/Source/platform/blob/BlobData.cpp

Issue 2717583003: [BlobStorage] Enforcing renderer constraints to prevent broken blobs (Closed)
Patch Set: added test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/blob/BlobData.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 80
81 std::unique_ptr<BlobData> BlobData::createForFileWithUnknownSize( 81 std::unique_ptr<BlobData> BlobData::createForFileWithUnknownSize(
82 const String& path) { 82 const String& path) {
83 std::unique_ptr<BlobData> data = WTF::wrapUnique( 83 std::unique_ptr<BlobData> data = WTF::wrapUnique(
84 new BlobData(FileCompositionStatus::SINGLE_UNKNOWN_SIZE_FILE)); 84 new BlobData(FileCompositionStatus::SINGLE_UNKNOWN_SIZE_FILE));
85 data->m_items.push_back(BlobDataItem(path)); 85 data->m_items.push_back(BlobDataItem(path));
86 return data; 86 return data;
87 } 87 }
88 88
89 std::unique_ptr<BlobData> BlobData::createForFileWithUnknownSize(
90 const String& path,
91 double expectedModificationTime) {
92 std::unique_ptr<BlobData> data = WTF::wrapUnique(
93 new BlobData(FileCompositionStatus::SINGLE_UNKNOWN_SIZE_FILE));
94 data->m_items.push_back(BlobDataItem(path, 0, BlobDataItem::toEndOfFile,
95 expectedModificationTime));
96 return data;
97 }
98
99 std::unique_ptr<BlobData> BlobData::createForFileSystemURLWithUnknownSize(
100 const KURL& fileSystemURL,
101 double expectedModificationTime) {
102 std::unique_ptr<BlobData> data = WTF::wrapUnique(
103 new BlobData(FileCompositionStatus::SINGLE_UNKNOWN_SIZE_FILE));
104 data->m_items.push_back(BlobDataItem(
105 fileSystemURL, 0, BlobDataItem::toEndOfFile, expectedModificationTime));
106 return data;
107 }
108
89 void BlobData::detachFromCurrentThread() { 109 void BlobData::detachFromCurrentThread() {
90 m_contentType = m_contentType.isolatedCopy(); 110 m_contentType = m_contentType.isolatedCopy();
91 for (size_t i = 0; i < m_items.size(); ++i) 111 for (size_t i = 0; i < m_items.size(); ++i)
92 m_items.at(i).detachFromCurrentThread(); 112 m_items.at(i).detachFromCurrentThread();
93 } 113 }
94 114
95 void BlobData::setContentType(const String& contentType) { 115 void BlobData::setContentType(const String& contentType) {
96 if (isValidBlobType(contentType)) 116 if (isValidBlobType(contentType))
97 m_contentType = contentType; 117 m_contentType = contentType;
98 else 118 else
99 m_contentType = ""; 119 m_contentType = "";
100 } 120 }
101 121
102 void BlobData::appendData(PassRefPtr<RawData> data, 122 void BlobData::appendData(PassRefPtr<RawData> data,
103 long long offset, 123 long long offset,
104 long long length) { 124 long long length) {
105 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 125 DCHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
106 << "Blobs with a unknown-size file cannot have other items."; 126 << "Blobs with a unknown-size file cannot have other items.";
107 m_items.push_back(BlobDataItem(std::move(data), offset, length)); 127 m_items.push_back(BlobDataItem(std::move(data), offset, length));
108 } 128 }
109 129
110 void BlobData::appendFile(const String& path, 130 void BlobData::appendFile(const String& path,
111 long long offset, 131 long long offset,
112 long long length, 132 long long length,
113 double expectedModificationTime) { 133 double expectedModificationTime) {
114 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 134 DCHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
115 << "Blobs with a unknown-size file cannot have other items."; 135 << "Blobs with a unknown-size file cannot have other items.";
136 DCHECK_NE(length, BlobDataItem::toEndOfFile)
137 << "It is illegal to append file items that have an unknown size. To "
138 "create a blob with a single file with unknown size, use "
139 "BlobData::createForFileWithUnknownSize. Otherwise please provide the "
140 "file size.";
116 m_items.push_back( 141 m_items.push_back(
117 BlobDataItem(path, offset, length, expectedModificationTime)); 142 BlobDataItem(path, offset, length, expectedModificationTime));
118 } 143 }
119 144
120 void BlobData::appendBlob(PassRefPtr<BlobDataHandle> dataHandle, 145 void BlobData::appendBlob(PassRefPtr<BlobDataHandle> dataHandle,
121 long long offset, 146 long long offset,
122 long long length) { 147 long long length) {
123 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 148 DCHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
124 << "Blobs with a unknown-size file cannot have other items."; 149 << "Blobs with a unknown-size file cannot have other items.";
150 DCHECK(!dataHandle->isSingleUnknownSizeFile())
151 << "It is illegal to append an unknown size file blob.";
125 m_items.push_back(BlobDataItem(std::move(dataHandle), offset, length)); 152 m_items.push_back(BlobDataItem(std::move(dataHandle), offset, length));
126 } 153 }
127 154
128 void BlobData::appendFileSystemURL(const KURL& url, 155 void BlobData::appendFileSystemURL(const KURL& url,
129 long long offset, 156 long long offset,
130 long long length, 157 long long length,
131 double expectedModificationTime) { 158 double expectedModificationTime) {
132 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 159 DCHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
133 << "Blobs with a unknown-size file cannot have other items."; 160 << "Blobs with a unknown-size file cannot have other items.";
134 m_items.push_back( 161 m_items.push_back(
135 BlobDataItem(url, offset, length, expectedModificationTime)); 162 BlobDataItem(url, offset, length, expectedModificationTime));
136 } 163 }
137 164
138 void BlobData::appendText(const String& text, 165 void BlobData::appendText(const String& text,
139 bool doNormalizeLineEndingsToNative) { 166 bool doNormalizeLineEndingsToNative) {
140 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 167 DCHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
141 << "Blobs with a unknown-size file cannot have other items."; 168 << "Blobs with a unknown-size file cannot have other items.";
142 CString utf8Text = UTF8Encoding().encode(text, WTF::EntitiesForUnencodables); 169 CString utf8Text = UTF8Encoding().encode(text, WTF::EntitiesForUnencodables);
143 RefPtr<RawData> data = nullptr; 170 RefPtr<RawData> data = nullptr;
144 Vector<char>* buffer; 171 Vector<char>* buffer;
145 if (canConsolidateData(text.length())) { 172 if (canConsolidateData(text.length())) {
146 buffer = m_items.back().data->mutableData(); 173 buffer = m_items.back().data->mutableData();
147 } else { 174 } else {
148 data = RawData::create(); 175 data = RawData::create();
149 buffer = data->mutableData(); 176 buffer = data->mutableData();
150 } 177 }
151 178
152 if (doNormalizeLineEndingsToNative) { 179 if (doNormalizeLineEndingsToNative) {
153 normalizeLineEndingsToNative(utf8Text, *buffer); 180 normalizeLineEndingsToNative(utf8Text, *buffer);
154 } else { 181 } else {
155 buffer->append(utf8Text.data(), utf8Text.length()); 182 buffer->append(utf8Text.data(), utf8Text.length());
156 } 183 }
157 184
158 if (data) 185 if (data)
159 m_items.push_back(BlobDataItem(std::move(data))); 186 m_items.push_back(BlobDataItem(std::move(data)));
160 } 187 }
161 188
162 void BlobData::appendBytes(const void* bytes, size_t length) { 189 void BlobData::appendBytes(const void* bytes, size_t length) {
163 CHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES) 190 DCHECK_EQ(m_fileComposition, FileCompositionStatus::NO_UNKNOWN_SIZE_FILES)
164 << "Blobs with a unknown-size file cannot have other items."; 191 << "Blobs with a unknown-size file cannot have other items.";
165 if (canConsolidateData(length)) { 192 if (canConsolidateData(length)) {
166 m_items.back().data->mutableData()->append(static_cast<const char*>(bytes), 193 m_items.back().data->mutableData()->append(static_cast<const char*>(bytes),
167 length); 194 length);
168 return; 195 return;
169 } 196 }
170 RefPtr<RawData> data = RawData::create(); 197 RefPtr<RawData> data = RawData::create();
171 Vector<char>* buffer = data->mutableData(); 198 Vector<char>* buffer = data->mutableData();
172 buffer->append(static_cast<const char*>(bytes), length); 199 buffer->append(static_cast<const char*>(bytes), length);
173 m_items.push_back(BlobDataItem(std::move(data))); 200 m_items.push_back(BlobDataItem(std::move(data)));
(...skipping 29 matching lines...) Expand all
203 return false; 230 return false;
204 BlobDataItem& lastItem = m_items.back(); 231 BlobDataItem& lastItem = m_items.back();
205 if (lastItem.type != BlobDataItem::Data) 232 if (lastItem.type != BlobDataItem::Data)
206 return false; 233 return false;
207 if (lastItem.data->length() + length > kMaxConsolidatedItemSizeInBytes) 234 if (lastItem.data->length() + length > kMaxConsolidatedItemSizeInBytes)
208 return false; 235 return false;
209 return true; 236 return true;
210 } 237 }
211 238
212 BlobDataHandle::BlobDataHandle() 239 BlobDataHandle::BlobDataHandle()
213 : m_uuid(createCanonicalUUIDString()), m_size(0) { 240 : m_uuid(createCanonicalUUIDString()),
241 m_size(0),
242 m_isSingleUnknownSizeFile(false) {
214 BlobRegistry::registerBlobData(m_uuid, BlobData::create()); 243 BlobRegistry::registerBlobData(m_uuid, BlobData::create());
215 } 244 }
216 245
217 BlobDataHandle::BlobDataHandle(std::unique_ptr<BlobData> data, long long size) 246 BlobDataHandle::BlobDataHandle(std::unique_ptr<BlobData> data, long long size)
218 : m_uuid(createCanonicalUUIDString()), 247 : m_uuid(createCanonicalUUIDString()),
219 m_type(data->contentType().isolatedCopy()), 248 m_type(data->contentType().isolatedCopy()),
220 m_size(size) { 249 m_size(size),
250 m_isSingleUnknownSizeFile(data->isSingleUnknownSizeFile()) {
221 BlobRegistry::registerBlobData(m_uuid, std::move(data)); 251 BlobRegistry::registerBlobData(m_uuid, std::move(data));
222 } 252 }
223 253
224 BlobDataHandle::BlobDataHandle(const String& uuid, 254 BlobDataHandle::BlobDataHandle(const String& uuid,
225 const String& type, 255 const String& type,
226 long long size) 256 long long size)
227 : m_uuid(uuid.isolatedCopy()), 257 : m_uuid(uuid.isolatedCopy()),
228 m_type(isValidBlobType(type) ? type.isolatedCopy() : ""), 258 m_type(isValidBlobType(type) ? type.isolatedCopy() : ""),
229 m_size(size) { 259 m_size(size),
260 m_isSingleUnknownSizeFile(false) {
230 BlobRegistry::addBlobDataRef(m_uuid); 261 BlobRegistry::addBlobDataRef(m_uuid);
231 } 262 }
232 263
233 BlobDataHandle::~BlobDataHandle() { 264 BlobDataHandle::~BlobDataHandle() {
234 BlobRegistry::removeBlobDataRef(m_uuid); 265 BlobRegistry::removeBlobDataRef(m_uuid);
235 } 266 }
236 267
237 } // namespace blink 268 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/blob/BlobData.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698