| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/child_process_sandbox_support_impl_linux.h" | 5 #include "content/child/child_process_sandbox_support_impl_linux.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "base/numerics/safe_conversions.h" | |
| 14 #include "base/pickle.h" | 13 #include "base/pickle.h" |
| 15 #include "base/posix/eintr_wrapper.h" | 14 #include "base/posix/eintr_wrapper.h" |
| 16 #include "base/posix/unix_domain_socket_linux.h" | 15 #include "base/posix/unix_domain_socket_linux.h" |
| 17 #include "base/sys_byteorder.h" | 16 #include "base/sys_byteorder.h" |
| 18 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 19 #include "content/common/sandbox_linux/sandbox_linux.h" | 18 #include "content/common/sandbox_linux/sandbox_linux.h" |
| 20 #include "third_party/WebKit/public/platform/linux/WebFallbackFont.h" | 19 #include "third_party/WebKit/public/platform/linux/WebFallbackFont.h" |
| 21 #include "third_party/WebKit/public/platform/linux/WebFontRenderStyle.h" | 20 #include "third_party/WebKit/public/platform/linux/WebFontRenderStyle.h" |
| 22 | 21 |
| 23 namespace content { | 22 namespace content { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 41 int fontconfigInterfaceId = 0; | 40 int fontconfigInterfaceId = 0; |
| 42 int ttcIndex = 0; | 41 int ttcIndex = 0; |
| 43 bool isBold = false; | 42 bool isBold = false; |
| 44 bool isItalic = false; | 43 bool isItalic = false; |
| 45 if (n != -1) { | 44 if (n != -1) { |
| 46 base::Pickle reply(reinterpret_cast<char*>(buf), n); | 45 base::Pickle reply(reinterpret_cast<char*>(buf), n); |
| 47 base::PickleIterator pickle_iter(reply); | 46 base::PickleIterator pickle_iter(reply); |
| 48 if (pickle_iter.ReadString(&family_name) && | 47 if (pickle_iter.ReadString(&family_name) && |
| 49 pickle_iter.ReadString(&filename) && | 48 pickle_iter.ReadString(&filename) && |
| 50 pickle_iter.ReadInt(&fontconfigInterfaceId) && | 49 pickle_iter.ReadInt(&fontconfigInterfaceId) && |
| 51 pickle_iter.ReadInt(&ttcIndex) && | 50 pickle_iter.ReadInt(&ttcIndex) && pickle_iter.ReadBool(&isBold) && |
| 52 pickle_iter.ReadBool(&isBold) && | |
| 53 pickle_iter.ReadBool(&isItalic)) { | 51 pickle_iter.ReadBool(&isItalic)) { |
| 54 fallbackFont->name = family_name; | 52 fallbackFont->name = family_name; |
| 55 fallbackFont->filename = filename; | 53 fallbackFont->filename = filename; |
| 56 fallbackFont->fontconfigInterfaceId = fontconfigInterfaceId; | 54 fallbackFont->fontconfigInterfaceId = fontconfigInterfaceId; |
| 57 fallbackFont->ttcIndex = ttcIndex; | 55 fallbackFont->ttcIndex = ttcIndex; |
| 58 fallbackFont->isBold = isBold; | 56 fallbackFont->isBold = isBold; |
| 59 fallbackFont->isItalic = isItalic; | 57 fallbackFont->isItalic = isItalic; |
| 60 } | 58 } |
| 61 } | 59 } |
| 62 } | 60 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 87 uint8_t buf[512]; | 85 uint8_t buf[512]; |
| 88 const ssize_t n = base::UnixDomainSocket::SendRecvMsg( | 86 const ssize_t n = base::UnixDomainSocket::SendRecvMsg( |
| 89 GetSandboxFD(), buf, sizeof(buf), NULL, request); | 87 GetSandboxFD(), buf, sizeof(buf), NULL, request); |
| 90 if (n == -1) | 88 if (n == -1) |
| 91 return; | 89 return; |
| 92 | 90 |
| 93 base::Pickle reply(reinterpret_cast<char*>(buf), n); | 91 base::Pickle reply(reinterpret_cast<char*>(buf), n); |
| 94 base::PickleIterator pickle_iter(reply); | 92 base::PickleIterator pickle_iter(reply); |
| 95 int use_bitmaps, use_autohint, use_hinting, hint_style, use_antialias; | 93 int use_bitmaps, use_autohint, use_hinting, hint_style, use_antialias; |
| 96 int use_subpixel_rendering, use_subpixel_positioning; | 94 int use_subpixel_rendering, use_subpixel_positioning; |
| 97 if (pickle_iter.ReadInt(&use_bitmaps) && | 95 if (pickle_iter.ReadInt(&use_bitmaps) && pickle_iter.ReadInt(&use_autohint) && |
| 98 pickle_iter.ReadInt(&use_autohint) && | 96 pickle_iter.ReadInt(&use_hinting) && pickle_iter.ReadInt(&hint_style) && |
| 99 pickle_iter.ReadInt(&use_hinting) && | |
| 100 pickle_iter.ReadInt(&hint_style) && | |
| 101 pickle_iter.ReadInt(&use_antialias) && | 97 pickle_iter.ReadInt(&use_antialias) && |
| 102 pickle_iter.ReadInt(&use_subpixel_rendering) && | 98 pickle_iter.ReadInt(&use_subpixel_rendering) && |
| 103 pickle_iter.ReadInt(&use_subpixel_positioning)) { | 99 pickle_iter.ReadInt(&use_subpixel_positioning)) { |
| 104 out->useBitmaps = use_bitmaps; | 100 out->useBitmaps = use_bitmaps; |
| 105 out->useAutoHint = use_autohint; | 101 out->useAutoHint = use_autohint; |
| 106 out->useHinting = use_hinting; | 102 out->useHinting = use_hinting; |
| 107 out->hintStyle = hint_style; | 103 out->hintStyle = hint_style; |
| 108 out->useAntiAlias = use_antialias; | 104 out->useAntiAlias = use_antialias; |
| 109 out->useSubpixelRendering = use_subpixel_rendering; | 105 out->useSubpixelRendering = use_subpixel_rendering; |
| 110 out->useSubpixelPositioning = use_subpixel_positioning; | 106 out->useSubpixelPositioning = use_subpixel_positioning; |
| 111 } | 107 } |
| 112 } | 108 } |
| 113 | 109 |
| 114 int MatchFontWithFallback(const std::string& face, | 110 int MatchFontWithFallback(const std::string& face, |
| 115 bool bold, | 111 bool bold, |
| 116 bool italic, | 112 bool italic, |
| 117 int charset, | 113 int charset, |
| 118 PP_BrowserFont_Trusted_Family fallback_family) { | 114 PP_BrowserFont_Trusted_Family fallback_family) { |
| 119 TRACE_EVENT0("sandbox_ipc", "MatchFontWithFallback"); | 115 TRACE_EVENT0("sandbox_ipc", "MatchFontWithFallback"); |
| 120 | 116 |
| 121 base::Pickle request; | 117 base::Pickle request; |
| 122 request.WriteInt(LinuxSandbox::METHOD_MATCH_WITH_FALLBACK); | 118 request.WriteInt(LinuxSandbox::METHOD_MATCH_WITH_FALLBACK); |
| 123 request.WriteString(face); | 119 request.WriteString(face); |
| 124 request.WriteBool(bold); | 120 request.WriteBool(bold); |
| 125 request.WriteBool(italic); | 121 request.WriteBool(italic); |
| 126 request.WriteUInt32(charset); | 122 request.WriteUInt32(charset); |
| 127 request.WriteUInt32(fallback_family); | 123 request.WriteUInt32(fallback_family); |
| 128 uint8_t reply_buf[64]; | 124 uint8_t reply_buf[64]; |
| 129 int fd = -1; | 125 int fd = -1; |
| 130 base::UnixDomainSocket::SendRecvMsg( | 126 base::UnixDomainSocket::SendRecvMsg(GetSandboxFD(), reply_buf, |
| 131 GetSandboxFD(), reply_buf, sizeof(reply_buf), &fd, request); | 127 sizeof(reply_buf), &fd, request); |
| 132 return fd; | 128 return fd; |
| 133 } | 129 } |
| 134 | 130 |
| 135 bool GetFontTable(int fd, uint32_t table_tag, off_t offset, | |
| 136 uint8_t* output, size_t* output_length) { | |
| 137 if (offset < 0) | |
| 138 return false; | |
| 139 | |
| 140 size_t data_length = 0; // the length of the file data. | |
| 141 off_t data_offset = 0; // the offset of the data in the file. | |
| 142 if (table_tag == 0) { | |
| 143 // Get the entire font file. | |
| 144 struct stat st; | |
| 145 if (fstat(fd, &st) < 0) | |
| 146 return false; | |
| 147 data_length = base::checked_cast<size_t>(st.st_size); | |
| 148 } else { | |
| 149 // Get a font table. Read the header to find its offset in the file. | |
| 150 uint16_t num_tables; | |
| 151 ssize_t n = HANDLE_EINTR(pread(fd, &num_tables, sizeof(num_tables), | |
| 152 4 /* skip the font type */)); | |
| 153 if (n != sizeof(num_tables)) | |
| 154 return false; | |
| 155 // Font data is stored in net (big-endian) order. | |
| 156 num_tables = base::NetToHost16(num_tables); | |
| 157 | |
| 158 // Read the table directory. | |
| 159 static const size_t kTableEntrySize = 16; | |
| 160 const size_t directory_size = num_tables * kTableEntrySize; | |
| 161 std::unique_ptr<uint8_t[]> table_entries(new uint8_t[directory_size]); | |
| 162 n = HANDLE_EINTR(pread(fd, table_entries.get(), directory_size, | |
| 163 12 /* skip the SFNT header */)); | |
| 164 if (n != base::checked_cast<ssize_t>(directory_size)) | |
| 165 return false; | |
| 166 | |
| 167 for (uint16_t i = 0; i < num_tables; ++i) { | |
| 168 uint8_t* entry = table_entries.get() + i * kTableEntrySize; | |
| 169 uint32_t tag = *reinterpret_cast<uint32_t*>(entry); | |
| 170 if (tag == table_tag) { | |
| 171 // Font data is stored in net (big-endian) order. | |
| 172 data_offset = | |
| 173 base::NetToHost32(*reinterpret_cast<uint32_t*>(entry + 8)); | |
| 174 data_length = | |
| 175 base::NetToHost32(*reinterpret_cast<uint32_t*>(entry + 12)); | |
| 176 break; | |
| 177 } | |
| 178 } | |
| 179 } | |
| 180 | |
| 181 if (!data_length) | |
| 182 return false; | |
| 183 // Clamp |offset| inside the allowable range. This allows the read to succeed | |
| 184 // but return 0 bytes. | |
| 185 offset = std::min(offset, base::checked_cast<off_t>(data_length)); | |
| 186 // Make sure it's safe to add the data offset and the caller's logical offset. | |
| 187 // Define the maximum positive offset on 32 bit systems. | |
| 188 static const off_t kMaxPositiveOffset32 = 0x7FFFFFFF; // 2 GB - 1. | |
| 189 if ((offset > kMaxPositiveOffset32 / 2) || | |
| 190 (data_offset > kMaxPositiveOffset32 / 2)) | |
| 191 return false; | |
| 192 data_offset += offset; | |
| 193 data_length -= offset; | |
| 194 | |
| 195 if (output) { | |
| 196 // 'output_length' holds the maximum amount of data the caller can accept. | |
| 197 data_length = std::min(data_length, *output_length); | |
| 198 ssize_t n = HANDLE_EINTR(pread(fd, output, data_length, data_offset)); | |
| 199 if (n != base::checked_cast<ssize_t>(data_length)) | |
| 200 return false; | |
| 201 } | |
| 202 *output_length = data_length; | |
| 203 | |
| 204 return true; | |
| 205 } | |
| 206 | |
| 207 } // namespace content | 131 } // namespace content |
| OLD | NEW |