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

Side by Side Diff: src/json-parser.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/hydrogen-instructions.cc ('k') | src/json-stringifier.h » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 // sequential string of type StringType. 599 // sequential string of type StringType.
600 template <bool seq_ascii> 600 template <bool seq_ascii>
601 template <typename StringType, typename SinkChar> 601 template <typename StringType, typename SinkChar>
602 Handle<String> JsonParser<seq_ascii>::SlowScanJsonString( 602 Handle<String> JsonParser<seq_ascii>::SlowScanJsonString(
603 Handle<String> prefix, int start, int end) { 603 Handle<String> prefix, int start, int end) {
604 int count = end - start; 604 int count = end - start;
605 int max_length = count + source_length_ - position_; 605 int max_length = count + source_length_ - position_;
606 int length = Min(max_length, Max(kInitialSpecialStringLength, 2 * count)); 606 int length = Min(max_length, Max(kInitialSpecialStringLength, 2 * count));
607 Handle<StringType> seq_string = 607 Handle<StringType> seq_string =
608 NewRawString<StringType>(factory(), length, pretenure_); 608 NewRawString<StringType>(factory(), length, pretenure_);
609 ASSERT(!seq_string.is_null());
609 // Copy prefix into seq_str. 610 // Copy prefix into seq_str.
610 SinkChar* dest = seq_string->GetChars(); 611 SinkChar* dest = seq_string->GetChars();
611 String::WriteToFlat(*prefix, dest, start, end); 612 String::WriteToFlat(*prefix, dest, start, end);
612 613
613 while (c0_ != '"') { 614 while (c0_ != '"') {
614 // Check for control character (0x00-0x1f) or unterminated string (<0). 615 // Check for control character (0x00-0x1f) or unterminated string (<0).
615 if (c0_ < 0x20) return Handle<String>::null(); 616 if (c0_ < 0x20) return Handle<String>::null();
616 if (count >= length) { 617 if (count >= length) {
617 // We need to create a longer sequential string for the result. 618 // We need to create a longer sequential string for the result.
618 return SlowScanJsonString<StringType, SinkChar>(seq_string, 0, count); 619 return SlowScanJsonString<StringType, SinkChar>(seq_string, 0, count);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 position_); 787 position_);
787 } 788 }
788 } else { 789 } else {
789 return SlowScanJsonString<SeqOneByteString, uint8_t>(source_, 790 return SlowScanJsonString<SeqOneByteString, uint8_t>(source_,
790 beg_pos, 791 beg_pos,
791 position_); 792 position_);
792 } 793 }
793 } while (c0_ != '"'); 794 } while (c0_ != '"');
794 int length = position_ - beg_pos; 795 int length = position_ - beg_pos;
795 Handle<String> result = factory()->NewRawOneByteString(length, pretenure_); 796 Handle<String> result = factory()->NewRawOneByteString(length, pretenure_);
797 ASSERT(!result.is_null());
796 uint8_t* dest = SeqOneByteString::cast(*result)->GetChars(); 798 uint8_t* dest = SeqOneByteString::cast(*result)->GetChars();
797 String::WriteToFlat(*source_, dest, beg_pos, position_); 799 String::WriteToFlat(*source_, dest, beg_pos, position_);
798 800
799 ASSERT_EQ('"', c0_); 801 ASSERT_EQ('"', c0_);
800 // Advance past the last '"'. 802 // Advance past the last '"'.
801 AdvanceSkipWhitespace(); 803 AdvanceSkipWhitespace();
802 return result; 804 return result;
803 } 805 }
804 806
805 } } // namespace v8::internal 807 } } // namespace v8::internal
806 808
807 #endif // V8_JSON_PARSER_H_ 809 #endif // V8_JSON_PARSER_H_
OLDNEW
« no previous file with comments | « src/hydrogen-instructions.cc ('k') | src/json-stringifier.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698