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

Unified Diff: runtime/vm/object.cc

Issue 23691013: Add checks catching potential integer overflows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index c36af942c07ae58ee40ce6268448f332d2db6f97..b2645a6986684aa564d364627ec4d78dcdd9e5cb 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -8122,8 +8122,7 @@ RawStackmap* Stackmap::New(intptr_t pc_offset,
intptr_t payload_size =
Utils::RoundUp(length, kBitsPerByte) / kBitsPerByte;
if ((payload_size < 0) ||
- (payload_size >
- (kSmiMax - static_cast<intptr_t>(sizeof(RawStackmap))))) {
+ (payload_size > kMaxLengthInBytes)) {
// This should be caught before we reach here.
FATAL1("Fatal error in Stackmap::New: invalid length %" Pd "\n",
length);
@@ -8547,6 +8546,10 @@ void DeoptInfo::PrintToJSONStream(JSONStream* stream, bool ref) const {
RawDeoptInfo* DeoptInfo::New(intptr_t num_commands) {
ASSERT(Object::deopt_info_class() != Class::null());
+ if ((num_commands < 0) || (num_commands > kMaxElements)) {
+ FATAL1("Fatal error in DeoptInfo::New(): invalid num_commands %" Pd "\n",
+ num_commands);
+ }
DeoptInfo& result = DeoptInfo::Handle();
{
uword size = DeoptInfo::InstanceSize(num_commands);
@@ -14361,13 +14364,11 @@ const intptr_t TypedData::element_size[] = {
RawTypedData* TypedData::New(intptr_t class_id,
intptr_t len,
Heap::Space space) {
- // TODO(asiva): Add a check for maximum elements.
+ if (len < 0 || len > TypedData::MaxElements(class_id)) {
+ FATAL1("Fatal error in TypedData::New: invalid len %" Pd "\n", len);
+ }
TypedData& result = TypedData::Handle();
{
- // The len field has already been checked by the caller, we only assert
- // here that it is within a valid range.
- ASSERT((len >= 0) &&
- (len < (kSmiMax / TypedData::ElementSizeInBytes(class_id))));
intptr_t lengthInBytes = len * ElementSizeInBytes(class_id);
RawObject* raw = Object::Allocate(class_id,
TypedData::InstanceSize(lengthInBytes),
« 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