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

Unified Diff: src/objects-inl.h

Issue 275016: Fix overflow in failure "requested size" field. (Closed)
Patch Set: Created 11 years, 2 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 | « src/objects.cc ('k') | src/string-stream.h » ('j') | src/string-stream.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index 662ad923baab283f55579ebe5c80f502bfda986e..cb7b7c881d0c5853138e2e48ad5abe0886816de2 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -778,7 +778,7 @@ int Failure::requested() const {
kFailureTypeTagSize + kSpaceTagSize - kObjectAlignmentBits;
STATIC_ASSERT(kShiftBits >= 0);
ASSERT(type() == RETRY_AFTER_GC);
- return value() >> kShiftBits;
+ return static_cast<int>(value() >> kShiftBits);
}
@@ -804,29 +804,31 @@ Failure* Failure::OutOfMemoryException() {
}
-int Failure::value() const {
- return static_cast<int>(reinterpret_cast<intptr_t>(this) >> kFailureTagSize);
+intptr_t Failure::value() const {
+ return reinterpret_cast<intptr_t>(this) >> kFailureTagSize;
}
Failure* Failure::RetryAfterGC(int requested_bytes) {
// Assert that the space encoding fits in the three bytes allotted for it.
ASSERT((LAST_SPACE & ~kSpaceTagMask) == 0);
- int requested = requested_bytes >> kObjectAlignmentBits;
+ intptr_t requested = requested_bytes >> kObjectAlignmentBits;
+ int tag_bits = kSpaceTagSize + kFailureTypeTagSize;
+ if (((requested << tag_bits) >> tag_bits) != requested) {
+ // No room for entire requested size in the bits. Round down to
+ // maximally representable size.
+ requested = static_cast<intptr_t>(
+ (~static_cast<uintptr_t>(0)) >> (tag_bits + 1));
+ }
int value = (requested << kSpaceTagSize) | NEW_SPACE;
- ASSERT(value >> kSpaceTagSize == requested);
- ASSERT(Smi::IsValid(value));
- ASSERT(value == ((value << kFailureTypeTagSize) >> kFailureTypeTagSize));
- ASSERT(Smi::IsValid(value << kFailureTypeTagSize));
return Construct(RETRY_AFTER_GC, value);
}
-Failure* Failure::Construct(Type type, int value) {
- int info = (value << kFailureTypeTagSize) | type;
+Failure* Failure::Construct(Type type, intptr_t value) {
+ intptr_t info = (static_cast<intptr_t>(value) << kFailureTypeTagSize) | type;
ASSERT(((info << kFailureTagSize) >> kFailureTagSize) == info);
- return reinterpret_cast<Failure*>(
- (static_cast<intptr_t>(info) << kFailureTagSize) | kFailureTag);
+ return reinterpret_cast<Failure*>((info << kFailureTagSize) | kFailureTag);
}
« no previous file with comments | « src/objects.cc ('k') | src/string-stream.h » ('j') | src/string-stream.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698