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

Side by Side Diff: src/uri.h

Issue 207613005: No longer OOM on invalid string length. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebase + addressed nits Created 6 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
« no previous file with comments | « src/runtime.cc ('k') | test/cctest/cctest.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 i += step; 120 i += step;
121 } 121 }
122 } 122 }
123 123
124 ASSERT(start_index < length); 124 ASSERT(start_index < length);
125 Handle<String> first_part = 125 Handle<String> first_part =
126 isolate->factory()->NewProperSubString(string, 0, start_index); 126 isolate->factory()->NewProperSubString(string, 0, start_index);
127 127
128 int dest_position = 0; 128 int dest_position = 0;
129 Handle<String> second_part; 129 Handle<String> second_part;
130 ASSERT(unescaped_length <= String::kMaxLength);
130 if (one_byte) { 131 if (one_byte) {
131 Handle<SeqOneByteString> dest = 132 Handle<SeqOneByteString> dest =
132 isolate->factory()->NewRawOneByteString(unescaped_length); 133 isolate->factory()->NewRawOneByteString(unescaped_length);
134 ASSERT(!dest.is_null());
133 DisallowHeapAllocation no_allocation; 135 DisallowHeapAllocation no_allocation;
134 Vector<const Char> vector = GetCharVector<Char>(string); 136 Vector<const Char> vector = GetCharVector<Char>(string);
135 for (int i = start_index; i < length; dest_position++) { 137 for (int i = start_index; i < length; dest_position++) {
136 int step; 138 int step;
137 dest->SeqOneByteStringSet(dest_position, 139 dest->SeqOneByteStringSet(dest_position,
138 UnescapeChar(vector, i, length, &step)); 140 UnescapeChar(vector, i, length, &step));
139 i += step; 141 i += step;
140 } 142 }
141 second_part = dest; 143 second_part = dest;
142 } else { 144 } else {
143 Handle<SeqTwoByteString> dest = 145 Handle<SeqTwoByteString> dest =
144 isolate->factory()->NewRawTwoByteString(unescaped_length); 146 isolate->factory()->NewRawTwoByteString(unescaped_length);
147 ASSERT(!dest.is_null());
145 DisallowHeapAllocation no_allocation; 148 DisallowHeapAllocation no_allocation;
146 Vector<const Char> vector = GetCharVector<Char>(string); 149 Vector<const Char> vector = GetCharVector<Char>(string);
147 for (int i = start_index; i < length; dest_position++) { 150 for (int i = start_index; i < length; dest_position++) {
148 int step; 151 int step;
149 dest->SeqTwoByteStringSet(dest_position, 152 dest->SeqTwoByteStringSet(dest_position,
150 UnescapeChar(vector, i, length, &step)); 153 UnescapeChar(vector, i, length, &step));
151 i += step; 154 i += step;
152 } 155 }
153 second_part = dest; 156 second_part = dest;
154 } 157 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 if (c >= 256) { 259 if (c >= 256) {
257 escaped_length += 6; 260 escaped_length += 6;
258 } else if (IsNotEscaped(c)) { 261 } else if (IsNotEscaped(c)) {
259 escaped_length++; 262 escaped_length++;
260 } else { 263 } else {
261 escaped_length += 3; 264 escaped_length += 3;
262 } 265 }
263 266
264 // We don't allow strings that are longer than a maximal length. 267 // We don't allow strings that are longer than a maximal length.
265 ASSERT(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow. 268 ASSERT(String::kMaxLength < 0x7fffffff - 6); // Cannot overflow.
266 if (escaped_length > String::kMaxLength) { 269 if (escaped_length > String::kMaxLength) break; // Provoke exception.
267 AllowHeapAllocation allocate_error_and_return;
268 isolate->ThrowInvalidStringLength();
269 return Handle<String>::null();
270 }
271 } 270 }
272 } 271 }
273 272
274 // No length change implies no change. Return original string if no change. 273 // No length change implies no change. Return original string if no change.
275 if (escaped_length == length) return string; 274 if (escaped_length == length) return string;
276 275
277 Handle<SeqOneByteString> dest = 276 Handle<SeqOneByteString> dest =
278 isolate->factory()->NewRawOneByteString(escaped_length); 277 isolate->factory()->NewRawOneByteString(escaped_length);
278 RETURN_IF_EMPTY_HANDLE_VALUE(isolate, dest, Handle<String>());
279 int dest_position = 0; 279 int dest_position = 0;
280 280
281 { DisallowHeapAllocation no_allocation; 281 { DisallowHeapAllocation no_allocation;
282 Vector<const Char> vector = GetCharVector<Char>(string); 282 Vector<const Char> vector = GetCharVector<Char>(string);
283 for (int i = 0; i < length; i++) { 283 for (int i = 0; i < length; i++) {
284 uint16_t c = vector[i]; 284 uint16_t c = vector[i];
285 if (c >= 256) { 285 if (c >= 256) {
286 dest->SeqOneByteStringSet(dest_position, '%'); 286 dest->SeqOneByteStringSet(dest_position, '%');
287 dest->SeqOneByteStringSet(dest_position+1, 'u'); 287 dest->SeqOneByteStringSet(dest_position+1, 'u');
288 dest->SeqOneByteStringSet(dest_position+2, kHexChars[c >> 12]); 288 dest->SeqOneByteStringSet(dest_position+2, kHexChars[c >> 12]);
(...skipping 12 matching lines...) Expand all
301 } 301 }
302 } 302 }
303 } 303 }
304 304
305 return dest; 305 return dest;
306 } 306 }
307 307
308 } } // namespace v8::internal 308 } } // namespace v8::internal
309 309
310 #endif // V8_URI_H_ 310 #endif // V8_URI_H_
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | test/cctest/cctest.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698