Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 1 | // Copyright 2016 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Ben Chan | 045849f | 2017-12-18 17:27:07 -0800 | [diff] [blame] | 5 | #include "imageloader/component.h" |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 6 | |
| 7 | #include <fcntl.h> |
| 8 | |
| 9 | #include <algorithm> |
| 10 | #include <string> |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 11 | #include <utility> |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
| 14 | #include <base/files/file.h> |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 15 | #include <base/files/file_enumerator.h> |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 16 | #include <base/files/file_path.h> |
| 17 | #include <base/files/file_util.h> |
| 18 | #include <base/files/scoped_file.h> |
| 19 | #include <base/json/json_string_value_serializer.h> |
| 20 | #include <base/logging.h> |
| 21 | #include <base/numerics/safe_conversions.h> |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 22 | #include <base/posix/eintr_wrapper.h> |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 23 | #include <base/strings/string_number_conversions.h> |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 24 | #include <base/strings/string_util.h> |
| 25 | #include <crypto/secure_hash.h> |
| 26 | #include <crypto/sha2.h> |
| 27 | #include <crypto/signature_verifier.h> |
| 28 | |
Greg Kerr | 09f06de | 2018-02-16 15:32:07 -0800 | [diff] [blame] | 29 | #include "imageloader/helper_process_proxy.h" |
Greg Kerr | 9944e24 | 2017-01-26 15:09:31 -0800 | [diff] [blame] | 30 | |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 31 | namespace imageloader { |
| 32 | |
| 33 | namespace { |
| 34 | |
| 35 | // The name of the imageloader manifest file. |
| 36 | constexpr char kManifestName[] = "imageloader.json"; |
| 37 | // The name of the fingerprint file. |
| 38 | constexpr char kFingerprintName[] = "manifest.fingerprint"; |
| 39 | // The manifest signature. |
Eric Caruso | 0b79bc8 | 2017-03-21 13:44:34 -0700 | [diff] [blame] | 40 | constexpr char kManifestSignatureNamePattern[] = "imageloader.sig.[1-2]"; |
Xiaochu Liu | c226434 | 2017-08-14 16:37:42 -0700 | [diff] [blame] | 41 | // The name of the image file (squashfs). |
| 42 | constexpr char kImageFileNameSquashFS[] = "image.squash"; |
| 43 | // The name of the image file (ext4). |
| 44 | constexpr char kImageFileNameExt4[] = "image.ext4"; |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 45 | // The name of the table file. |
| 46 | constexpr char kTableFileName[] = "table"; |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 47 | |
| 48 | base::FilePath GetManifestPath(const base::FilePath& component_dir) { |
| 49 | return component_dir.Append(kManifestName); |
| 50 | } |
| 51 | |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 52 | bool GetSignaturePath(const base::FilePath& component_dir, |
| 53 | base::FilePath* signature_path, |
Eric Caruso | 9588e64 | 2017-04-07 15:18:45 -0700 | [diff] [blame] | 54 | size_t* key_number) { |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 55 | DCHECK(signature_path); |
| 56 | DCHECK(key_number); |
| 57 | |
Greg Kerr | 09f06de | 2018-02-16 15:32:07 -0800 | [diff] [blame] | 58 | base::FileEnumerator files(component_dir, false, |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 59 | base::FileEnumerator::FileType::FILES, |
| 60 | kManifestSignatureNamePattern); |
| 61 | for (base::FilePath path = files.Next(); !path.empty(); path = files.Next()) { |
| 62 | // Extract the key number. |
| 63 | std::string key_ext = path.FinalExtension(); |
| 64 | if (key_ext.empty()) |
| 65 | continue; |
| 66 | |
Eric Caruso | 9588e64 | 2017-04-07 15:18:45 -0700 | [diff] [blame] | 67 | size_t ext_number; |
| 68 | if (!base::StringToSizeT(key_ext.substr(1), &ext_number)) |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 69 | continue; |
| 70 | |
| 71 | *signature_path = path; |
| 72 | *key_number = ext_number; |
| 73 | return true; |
| 74 | } |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | base::FilePath GetSignaturePathForKey(const base::FilePath& component_dir, |
Eric Caruso | 9588e64 | 2017-04-07 15:18:45 -0700 | [diff] [blame] | 79 | size_t key_number) { |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 80 | std::string signature_name(kManifestSignatureNamePattern); |
| 81 | signature_name = |
| 82 | signature_name.substr(0, signature_name.find_last_of('.') + 1); |
Hidehiko Abe | 0deb054 | 2019-08-15 01:56:10 +0900 | [diff] [blame^] | 83 | return component_dir.Append(signature_name + |
| 84 | base::NumberToString(key_number)); |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | base::FilePath GetFingerprintPath(const base::FilePath& component_dir) { |
| 88 | return component_dir.Append(kFingerprintName); |
| 89 | } |
| 90 | |
| 91 | base::FilePath GetTablePath(const base::FilePath& component_dir) { |
| 92 | return component_dir.Append(kTableFileName); |
| 93 | } |
| 94 | |
Xiaochu Liu | c226434 | 2017-08-14 16:37:42 -0700 | [diff] [blame] | 95 | base::FilePath GetImagePath(const base::FilePath& component_dir, |
Xiaochu Liu | e61e1d6 | 2018-11-12 13:20:09 -0800 | [diff] [blame] | 96 | FileSystem fs_type) { |
| 97 | if (fs_type == FileSystem::kExt4) { |
Xiaochu Liu | c226434 | 2017-08-14 16:37:42 -0700 | [diff] [blame] | 98 | return component_dir.Append(kImageFileNameExt4); |
Xiaochu Liu | e61e1d6 | 2018-11-12 13:20:09 -0800 | [diff] [blame] | 99 | } else if (fs_type == FileSystem::kSquashFS) { |
Xiaochu Liu | c226434 | 2017-08-14 16:37:42 -0700 | [diff] [blame] | 100 | return component_dir.Append(kImageFileNameSquashFS); |
Greg Kerr | 09f06de | 2018-02-16 15:32:07 -0800 | [diff] [blame] | 101 | } else { |
Xiaochu Liu | c226434 | 2017-08-14 16:37:42 -0700 | [diff] [blame] | 102 | NOTREACHED(); |
| 103 | return base::FilePath(); |
| 104 | } |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | bool WriteFileToDisk(const base::FilePath& path, const std::string& contents) { |
Greg Kerr | 09f06de | 2018-02-16 15:32:07 -0800 | [diff] [blame] | 108 | base::ScopedFD fd(HANDLE_EINTR(open( |
| 109 | path.value().c_str(), O_CREAT | O_WRONLY | O_EXCL, kComponentFilePerms))); |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 110 | if (!fd.is_valid()) { |
| 111 | PLOG(ERROR) << "Error creating file for " << path.value(); |
| 112 | return false; |
| 113 | } |
| 114 | |
| 115 | base::File file(fd.release()); |
| 116 | int size = base::checked_cast<int>(contents.size()); |
| 117 | return file.Write(0, contents.data(), contents.size()) == size; |
| 118 | } |
| 119 | |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 120 | bool GetAndVerifyTable(const base::FilePath& path, |
| 121 | const std::vector<uint8_t>& hash, |
| 122 | std::string* out_table) { |
| 123 | std::string table; |
| 124 | if (!base::ReadFileToStringWithMaxSize(path, &table, kMaximumFilesize)) { |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | std::vector<uint8_t> table_hash(crypto::kSHA256Length); |
| 129 | crypto::SHA256HashString(table, table_hash.data(), table_hash.size()); |
| 130 | if (table_hash != hash) { |
| 131 | LOG(ERROR) << "dm-verity table file has the wrong hash."; |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | out_table->assign(table); |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | } // namespace |
| 140 | |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 141 | Component::Component(const base::FilePath& component_dir, int key_number) |
| 142 | : component_dir_(component_dir), key_number_(key_number) {} |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 143 | |
Eric Caruso | cbe1c5c | 2017-03-15 14:21:08 -0700 | [diff] [blame] | 144 | std::unique_ptr<Component> Component::Create( |
Greg Kerr | 09f06de | 2018-02-16 15:32:07 -0800 | [diff] [blame] | 145 | const base::FilePath& component_dir, const Keys& public_keys) { |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 146 | base::FilePath signature_path; |
Eric Caruso | 9588e64 | 2017-04-07 15:18:45 -0700 | [diff] [blame] | 147 | size_t key_number; |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 148 | if (!GetSignaturePath(component_dir, &signature_path, &key_number)) { |
| 149 | LOG(ERROR) << "Could not find manifest signature"; |
| 150 | return nullptr; |
| 151 | } |
Eric Caruso | 0b79bc8 | 2017-03-21 13:44:34 -0700 | [diff] [blame] | 152 | if (key_number < 1 || key_number > public_keys.size()) { |
| 153 | LOG(ERROR) << "Invalid key number"; |
| 154 | return nullptr; |
| 155 | } |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 156 | |
| 157 | std::unique_ptr<Component> component( |
| 158 | new Component(component_dir, key_number)); |
Eric Caruso | 0b79bc8 | 2017-03-21 13:44:34 -0700 | [diff] [blame] | 159 | if (!component->LoadManifest(public_keys[key_number - 1])) |
Eric Caruso | cbe1c5c | 2017-03-15 14:21:08 -0700 | [diff] [blame] | 160 | return nullptr; |
| 161 | return component; |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Xiaochu Liu | e61e1d6 | 2018-11-12 13:20:09 -0800 | [diff] [blame] | 164 | const Manifest& Component::manifest() { |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 165 | return manifest_; |
| 166 | } |
| 167 | |
Greg Kerr | 09f06de | 2018-02-16 15:32:07 -0800 | [diff] [blame] | 168 | bool Component::Mount(HelperProcessProxy* mounter, |
| 169 | const base::FilePath& dest_dir) { |
Eric Caruso | cbe1c5c | 2017-03-15 14:21:08 -0700 | [diff] [blame] | 170 | // Read the table in and verify the hash. |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 171 | std::string table; |
Xiaochu Liu | c209aab | 2018-06-19 13:42:15 -0700 | [diff] [blame] | 172 | if (!GetAndVerifyTable(GetTablePath(component_dir_), manifest_.table_sha256(), |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 173 | &table)) { |
| 174 | LOG(ERROR) << "Could not read and verify dm-verity table."; |
| 175 | return false; |
| 176 | } |
| 177 | |
Xiaochu Liu | c209aab | 2018-06-19 13:42:15 -0700 | [diff] [blame] | 178 | base::FilePath image_path(GetImagePath(component_dir_, manifest_.fs_type())); |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 179 | base::File image(image_path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
| 180 | if (!image.IsValid()) { |
| 181 | LOG(ERROR) << "Could not open image file."; |
| 182 | return false; |
| 183 | } |
| 184 | base::ScopedFD image_fd(image.TakePlatformFile()); |
| 185 | |
Xiaochu Liu | c226434 | 2017-08-14 16:37:42 -0700 | [diff] [blame] | 186 | return mounter->SendMountCommand(image_fd.get(), dest_dir.value(), |
Xiaochu Liu | c209aab | 2018-06-19 13:42:15 -0700 | [diff] [blame] | 187 | manifest_.fs_type(), table); |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | bool Component::LoadManifest(const std::vector<uint8_t>& public_key) { |
| 191 | if (!base::ReadFileToStringWithMaxSize(GetManifestPath(component_dir_), |
| 192 | &manifest_raw_, kMaximumFilesize)) { |
| 193 | LOG(ERROR) << "Could not read manifest file."; |
| 194 | return false; |
| 195 | } |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 196 | if (!base::ReadFileToStringWithMaxSize( |
Greg Kerr | 09f06de | 2018-02-16 15:32:07 -0800 | [diff] [blame] | 197 | GetSignaturePathForKey(component_dir_, key_number_), &manifest_sig_, |
| 198 | kMaximumFilesize)) { |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 199 | LOG(ERROR) << "Could not read signature file."; |
| 200 | return false; |
| 201 | } |
| 202 | |
| 203 | crypto::SignatureVerifier verifier; |
| 204 | |
| 205 | if (!verifier.VerifyInit( |
| 206 | crypto::SignatureVerifier::ECDSA_SHA256, |
| 207 | reinterpret_cast<const uint8_t*>(manifest_sig_.data()), |
| 208 | base::checked_cast<int>(manifest_sig_.size()), public_key.data(), |
| 209 | base::checked_cast<int>(public_key.size()))) { |
| 210 | LOG(ERROR) << "Failed to initialize signature verification."; |
| 211 | return false; |
| 212 | } |
| 213 | |
| 214 | verifier.VerifyUpdate(reinterpret_cast<const uint8_t*>(manifest_raw_.data()), |
| 215 | base::checked_cast<int>(manifest_raw_.size())); |
| 216 | |
| 217 | if (!verifier.VerifyFinal()) { |
| 218 | LOG(ERROR) << "Manifest failed signature verification."; |
| 219 | return false; |
| 220 | } |
Xiaochu Liu | c209aab | 2018-06-19 13:42:15 -0700 | [diff] [blame] | 221 | return manifest_.ParseManifest(manifest_raw_); |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | bool Component::CopyTo(const base::FilePath& dest_dir) { |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 225 | if (!WriteFileToDisk(GetManifestPath(dest_dir), manifest_raw_) || |
Eric Caruso | 089bbff | 2017-03-21 11:34:15 -0700 | [diff] [blame] | 226 | !WriteFileToDisk(GetSignaturePathForKey(dest_dir, key_number_), |
Greg Kerr | 09f06de | 2018-02-16 15:32:07 -0800 | [diff] [blame] | 227 | manifest_sig_)) { |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 228 | LOG(ERROR) << "Could not write manifest and signature to disk."; |
| 229 | return false; |
| 230 | } |
| 231 | |
| 232 | base::FilePath table_src(GetTablePath(component_dir_)); |
| 233 | base::FilePath table_dest(GetTablePath(dest_dir)); |
Xiaochu Liu | c209aab | 2018-06-19 13:42:15 -0700 | [diff] [blame] | 234 | if (!CopyComponentFile(table_src, table_dest, manifest_.table_sha256())) { |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 235 | LOG(ERROR) << "Could not copy table file."; |
| 236 | return false; |
| 237 | } |
| 238 | |
Xiaochu Liu | c209aab | 2018-06-19 13:42:15 -0700 | [diff] [blame] | 239 | base::FilePath image_src(GetImagePath(component_dir_, manifest_.fs_type())); |
| 240 | base::FilePath image_dest(GetImagePath(dest_dir, manifest_.fs_type())); |
| 241 | if (!CopyComponentFile(image_src, image_dest, manifest_.image_sha256())) { |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 242 | LOG(ERROR) << "Could not copy image file."; |
| 243 | return false; |
| 244 | } |
| 245 | |
| 246 | if (!CopyFingerprintFile(component_dir_, dest_dir)) { |
| 247 | LOG(ERROR) << "Could not copy manifest.fingerprint file."; |
| 248 | return false; |
| 249 | } |
| 250 | |
| 251 | return true; |
| 252 | } |
| 253 | |
| 254 | bool Component::CopyComponentFile(const base::FilePath& src, |
Eric Caruso | 355e37c | 2017-03-15 14:31:41 -0700 | [diff] [blame] | 255 | const base::FilePath& dest_path, |
| 256 | const std::vector<uint8_t>& expected_hash) { |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 257 | base::File file(src, base::File::FLAG_OPEN | base::File::FLAG_READ); |
Eric Caruso | 355e37c | 2017-03-15 14:31:41 -0700 | [diff] [blame] | 258 | if (!file.IsValid()) |
| 259 | return false; |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 260 | |
| 261 | base::ScopedFD dest( |
| 262 | HANDLE_EINTR(open(dest_path.value().c_str(), O_CREAT | O_WRONLY | O_EXCL, |
| 263 | kComponentFilePerms))); |
Eric Caruso | 355e37c | 2017-03-15 14:31:41 -0700 | [diff] [blame] | 264 | if (!dest.is_valid()) |
| 265 | return false; |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 266 | |
| 267 | base::File out_file(dest.release()); |
| 268 | std::unique_ptr<crypto::SecureHash> sha256( |
| 269 | crypto::SecureHash::Create(crypto::SecureHash::SHA256)); |
| 270 | |
| 271 | std::vector<uint8_t> file_hash(crypto::kSHA256Length); |
| 272 | if (!ReadHashAndCopyFile(&file, &file_hash, &out_file)) { |
| 273 | LOG(ERROR) << "Failed to read image file."; |
| 274 | return false; |
| 275 | } |
| 276 | |
| 277 | if (expected_hash != file_hash) { |
| 278 | LOG(ERROR) << "Image is corrupt or modified."; |
| 279 | return false; |
| 280 | } |
| 281 | return true; |
| 282 | } |
| 283 | |
| 284 | bool Component::ReadHashAndCopyFile(base::File* file, |
| 285 | std::vector<uint8_t>* file_hash, |
| 286 | base::File* out_file) { |
| 287 | std::unique_ptr<crypto::SecureHash> sha256( |
| 288 | crypto::SecureHash::Create(crypto::SecureHash::SHA256)); |
| 289 | int size = file->GetLength(); |
Eric Caruso | 355e37c | 2017-03-15 14:31:41 -0700 | [diff] [blame] | 290 | if (size <= 0) |
| 291 | return false; |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 292 | |
| 293 | int rv = 0, bytes_read = 0; |
| 294 | char buf[4096]; |
| 295 | do { |
| 296 | int remaining = size - bytes_read; |
| 297 | int bytes_to_read = |
| 298 | std::min(remaining, base::checked_cast<int>(sizeof(buf))); |
| 299 | |
| 300 | rv = file->ReadAtCurrentPos(buf, bytes_to_read); |
Greg Kerr | 09f06de | 2018-02-16 15:32:07 -0800 | [diff] [blame] | 301 | if (rv <= 0) |
| 302 | break; |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 303 | |
| 304 | bytes_read += rv; |
| 305 | sha256->Update(buf, rv); |
| 306 | if (out_file) { |
| 307 | out_file->WriteAtCurrentPos(buf, rv); |
| 308 | } |
| 309 | } while (bytes_read <= size); |
| 310 | |
| 311 | sha256->Finish(file_hash->data(), file_hash->size()); |
| 312 | return bytes_read == size; |
| 313 | } |
| 314 | |
| 315 | bool Component::CopyFingerprintFile(const base::FilePath& src, |
| 316 | const base::FilePath& dest) { |
| 317 | base::FilePath fingerprint_path(GetFingerprintPath(src)); |
| 318 | if (base::PathExists(fingerprint_path)) { |
| 319 | std::string fingerprint_contents; |
| 320 | if (!base::ReadFileToStringWithMaxSize( |
| 321 | fingerprint_path, &fingerprint_contents, kMaximumFilesize)) { |
| 322 | return false; |
| 323 | } |
| 324 | |
Eric Caruso | 355e37c | 2017-03-15 14:31:41 -0700 | [diff] [blame] | 325 | if (!IsValidFingerprintFile(fingerprint_contents)) |
| 326 | return false; |
Greg Kerr | 019d59c | 2016-11-17 14:28:49 -0800 | [diff] [blame] | 327 | |
| 328 | if (!WriteFileToDisk(GetFingerprintPath(dest), fingerprint_contents)) { |
| 329 | return false; |
| 330 | } |
| 331 | } |
| 332 | return true; |
| 333 | } |
| 334 | |
| 335 | // The client inserts manifest.fingerprint into components after unpacking the |
| 336 | // CRX. The file is used for delta updates. Since Chrome OS doesn't rely on it |
| 337 | // for security of the disk image, we are fine with sanity checking the contents |
| 338 | // and then preserving the unsigned file. |
| 339 | bool Component::IsValidFingerprintFile(const std::string& contents) { |
| 340 | return contents.size() <= 256 && |
| 341 | std::find_if_not(contents.begin(), contents.end(), [](char ch) { |
| 342 | return base::IsAsciiAlpha(ch) || base::IsAsciiDigit(ch) || ch == '.'; |
| 343 | }) == contents.end(); |
| 344 | } |
| 345 | |
| 346 | } // namespace imageloader |