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

Side by Side Diff: src/factory.cc

Issue 63173023: Avoid integer overflow in CopyMap. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 1 month 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 | « no previous file | no next file » | 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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 619
620 620
621 Handle<Map> Factory::CopyMap(Handle<Map> src, 621 Handle<Map> Factory::CopyMap(Handle<Map> src,
622 int extra_inobject_properties) { 622 int extra_inobject_properties) {
623 Handle<Map> copy = CopyWithPreallocatedFieldDescriptors(src); 623 Handle<Map> copy = CopyWithPreallocatedFieldDescriptors(src);
624 // Check that we do not overflow the instance size when adding the 624 // Check that we do not overflow the instance size when adding the
625 // extra inobject properties. 625 // extra inobject properties.
626 int instance_size_delta = extra_inobject_properties * kPointerSize; 626 int instance_size_delta = extra_inobject_properties * kPointerSize;
627 int max_instance_size_delta = 627 int max_instance_size_delta =
628 JSObject::kMaxInstanceSize - copy->instance_size(); 628 JSObject::kMaxInstanceSize - copy->instance_size();
629 if (instance_size_delta > max_instance_size_delta) { 629 int max_extra_properties = max_instance_size_delta >> kPointerSizeLog2;
630 if (extra_inobject_properties > max_extra_properties) {
630 // If the instance size overflows, we allocate as many properties 631 // If the instance size overflows, we allocate as many properties
631 // as we can as inobject properties. 632 // as we can as inobject properties.
632 instance_size_delta = max_instance_size_delta; 633 instance_size_delta = max_instance_size_delta;
633 extra_inobject_properties = max_instance_size_delta >> kPointerSizeLog2; 634 extra_inobject_properties = max_extra_properties;
634 } 635 }
635 // Adjust the map with the extra inobject properties. 636 // Adjust the map with the extra inobject properties.
636 int inobject_properties = 637 int inobject_properties =
637 copy->inobject_properties() + extra_inobject_properties; 638 copy->inobject_properties() + extra_inobject_properties;
638 copy->set_inobject_properties(inobject_properties); 639 copy->set_inobject_properties(inobject_properties);
639 copy->set_unused_property_fields(inobject_properties); 640 copy->set_unused_property_fields(inobject_properties);
640 copy->set_instance_size(copy->instance_size() + instance_size_delta); 641 copy->set_instance_size(copy->instance_size() + instance_size_delta);
641 copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy)); 642 copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy));
642 return copy; 643 return copy;
643 } 644 }
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1787 return Handle<Object>::null(); 1788 return Handle<Object>::null();
1788 } 1789 }
1789 1790
1790 1791
1791 Handle<Object> Factory::ToBoolean(bool value) { 1792 Handle<Object> Factory::ToBoolean(bool value) {
1792 return value ? true_value() : false_value(); 1793 return value ? true_value() : false_value();
1793 } 1794 }
1794 1795
1795 1796
1796 } } // namespace v8::internal 1797 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698