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

Side by Side Diff: content/common/child_process_sandbox_support_impl_linux.cc

Issue 12433021: Modify content::GetFontTable so clients can control what is read. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/child_process_sandbox_support_impl_linux.h"
6 6
7 #include <sys/stat.h> 7 #include <sys/stat.h>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 request.WriteBool(italic); 93 request.WriteBool(italic);
94 request.WriteUInt32(charset); 94 request.WriteUInt32(charset);
95 uint8_t reply_buf[64]; 95 uint8_t reply_buf[64];
96 int fd = -1; 96 int fd = -1;
97 UnixDomainSocket::SendRecvMsg(GetSandboxFD(), reply_buf, sizeof(reply_buf), 97 UnixDomainSocket::SendRecvMsg(GetSandboxFD(), reply_buf, sizeof(reply_buf),
98 &fd, request); 98 &fd, request);
99 return fd; 99 return fd;
100 } 100 }
101 101
102 bool GetFontTable(int fd, uint32_t table, uint8_t* output, 102 bool GetFontTable(int fd, uint32_t table, uint8_t* output,
103 size_t* output_length) { 103 size_t* output_length, size_t offset) {
104 if (table == 0) { 104 if (table == 0) {
105 struct stat st; 105 struct stat st;
106 if (fstat(fd, &st) < 0) 106 if (fstat(fd, &st) < 0)
107 return false; 107 return false;
108 size_t length = st.st_size; 108 size_t length = st.st_size;
109 if (offset > length)
110 return false;
111 length -= offset;
109 if (!output) { 112 if (!output) {
110 *output_length = length; 113 *output_length = length;
111 return true; 114 return true;
112 } 115 }
113 if (*output_length < length) 116 length = std::min(length, *output_length);
114 return false;
115 *output_length = length; 117 *output_length = length;
116 ssize_t n = HANDLE_EINTR(pread(fd, output, length, 0)); 118 ssize_t n = HANDLE_EINTR(pread(fd, output, length, offset));
117 if (n != static_cast<ssize_t>(length)) 119 if (n != static_cast<ssize_t>(length))
118 return false; 120 return false;
119 return true; 121 return true;
120 } 122 }
121 123
122 unsigned num_tables; 124 unsigned num_tables;
123 uint8_t num_tables_buf[2]; 125 uint8_t num_tables_buf[2];
124 126
125 ssize_t n = HANDLE_EINTR(pread(fd, &num_tables_buf, sizeof(num_tables_buf), 127 ssize_t n = HANDLE_EINTR(pread(fd, &num_tables_buf, sizeof(num_tables_buf),
126 4 /* skip the font type */)); 128 4 /* skip the font type */));
127 if (n != sizeof(num_tables_buf)) 129 if (n != sizeof(num_tables_buf))
128 return false; 130 return false;
129 131
130 num_tables = static_cast<unsigned>(num_tables_buf[0]) << 8 | 132 num_tables = static_cast<unsigned>(num_tables_buf[0]) << 8 |
131 num_tables_buf[1]; 133 num_tables_buf[1];
132 134
133 // The size in bytes of an entry in the table directory. 135 // The size in bytes of an entry in the table directory.
134 static const unsigned kTableEntrySize = 16; 136 static const unsigned kTableEntrySize = 16;
135 scoped_array<uint8_t> table_entries( 137 scoped_array<uint8_t> table_entries(
136 new uint8_t[num_tables * kTableEntrySize]); 138 new uint8_t[num_tables * kTableEntrySize]);
137 n = HANDLE_EINTR(pread(fd, table_entries.get(), num_tables * kTableEntrySize, 139 n = HANDLE_EINTR(pread(fd, table_entries.get(), num_tables * kTableEntrySize,
138 12 /* skip the SFNT header */)); 140 12 /* skip the SFNT header */));
139 if (n != static_cast<ssize_t>(num_tables * kTableEntrySize)) 141 if (n != static_cast<ssize_t>(num_tables * kTableEntrySize))
140 return false; 142 return false;
141 143
142 size_t offset; 144 size_t table_offset = 0;
143 size_t length = 0; 145 size_t length = 0;
144 for (unsigned i = 0; i < num_tables; i++) { 146 for (unsigned i = 0; i < num_tables; i++) {
145 const uint8_t* entry = table_entries.get() + i * kTableEntrySize; 147 const uint8_t* entry = table_entries.get() + i * kTableEntrySize;
146 if (memcmp(entry, &table, sizeof(table)) == 0) { 148 if (memcmp(entry, &table, sizeof(table)) == 0) {
147 offset = static_cast<size_t>(entry[8]) << 24 | 149 table_offset = static_cast<size_t>(entry[8]) << 24 |
148 static_cast<size_t>(entry[9]) << 16 | 150 static_cast<size_t>(entry[9]) << 16 |
149 static_cast<size_t>(entry[10]) << 8 | 151 static_cast<size_t>(entry[10]) << 8 |
150 static_cast<size_t>(entry[11]); 152 static_cast<size_t>(entry[11]);
151 length = static_cast<size_t>(entry[12]) << 24 | 153 length = static_cast<size_t>(entry[12]) << 24 |
152 static_cast<size_t>(entry[13]) << 16 | 154 static_cast<size_t>(entry[13]) << 16 |
153 static_cast<size_t>(entry[14]) << 8 | 155 static_cast<size_t>(entry[14]) << 8 |
154 static_cast<size_t>(entry[15]); 156 static_cast<size_t>(entry[15]);
155 157
156 break; 158 break;
157 } 159 }
158 } 160 }
159 161
160 if (!length) 162 if (!length || offset > length)
161 return false; 163 return false;
164 length -= offset;
162 165
163 if (!output) { 166 if (!output) {
164 *output_length = length; 167 *output_length = length;
165 return true; 168 return true;
166 } 169 }
167 170
168 if (*output_length < length) 171 length = std::min(length, *output_length);
169 return false;
170
171 *output_length = length; 172 *output_length = length;
172 n = HANDLE_EINTR(pread(fd, output, length, offset)); 173 n = HANDLE_EINTR(pread(fd, output, length, table_offset + offset));
173 if (n != static_cast<ssize_t>(length)) 174 if (n != static_cast<ssize_t>(length))
174 return false; 175 return false;
175 176
176 return true; 177 return true;
177 } 178 }
178 179
179 } // namespace content 180 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698