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

Unified Diff: src/v8conversions.h

Issue 72323003: Harden NumberToSize against overflows. (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 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: src/v8conversions.h
diff --git a/src/v8conversions.h b/src/v8conversions.h
index 3a7b5242ab79af659b15e99b0a6d53f967cd91d1..f3d0992d62b2ccb030b54f260cce604d0ec20ec5 100644
--- a/src/v8conversions.h
+++ b/src/v8conversions.h
@@ -60,10 +60,15 @@ inline size_t NumberToSize(Isolate* isolate,
Object* number) {
SealHandleScope shs(isolate);
if (number->IsSmi()) {
+ int value = Smi::cast(number)->value();
+ CHECK(value >= 0
Jakob Kummerow 2013/11/14 10:17:48 Not that it makes a big difference, but it's suffi
Dmitry Lomov (no reviews) 2013/11/14 10:22:58 Great suggestion, this is by far the commonest cas
+ && static_cast<unsigned>(value) <= std::numeric_limits<size_t>::max());
return Smi::cast(number)->value();
} else {
ASSERT(number->IsHeapNumber());
double value = HeapNumber::cast(number)->value();
+ CHECK(value >= 0 &&
+ value <= std::numeric_limits<size_t>::max());
Jakob Kummerow 2013/11/14 10:17:48 nit: I'd align "value" with "value".
return static_cast<size_t>(value);
}
}
« 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