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

Unified Diff: chrome/renderer/resources/json_schema.js

Issue 7042021: Check for integer overflow when validating API function arguments. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 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
Index: chrome/renderer/resources/json_schema.js
diff --git a/chrome/renderer/resources/json_schema.js b/chrome/renderer/resources/json_schema.js
index caac22b0a2334680578319ca10974078a95a56ab..3edde15d6d9c76d69e71c011b2087e4e2584e61b 100644
--- a/chrome/renderer/resources/json_schema.js
+++ b/chrome/renderer/resources/json_schema.js
@@ -75,6 +75,7 @@ chromeHidden.JSONSchemaValidator.messages = {
numberFiniteNotNan: "Value must not be *.",
numberMinValue: "Value must not be less than *.",
numberMaxValue: "Value must not be greater than *.",
+ numberIntValue: "Value must fit in a 32-bit signed integer.",
numberMaxDecimal: "Value must not have more than * decimal places.",
invalidType: "Expected '*' but got '*'.",
invalidChoice: "Value does not match any valid type choices.",
@@ -410,6 +411,10 @@ chromeHidden.JSONSchemaValidator.prototype.validateNumber = function(
if (schema.maximum && instance > schema.maximum)
this.addError(path, "numberMaxValue", [schema.maximum]);
+ // Check for integer values outside of -2^31..2^31-1.
+ if (schema.type == "integer" && (instance | 0) != instance)
asargent_no_longer_on_chrome 2011/05/19 18:36:48 Kasper - can you confirm that this will continue t
Ben Olmstead 2011/05/19 20:34:18 Truncation to 32 bits is actually specified by ECM
arv (Not doing code reviews) 2011/05/19 21:10:04 Bitwise or is a good way to do ToInt32. You should
+ this.addError(path, "numberIntValue", []);
+
if (schema.maxDecimal && instance * Math.pow(10, schema.maxDecimal) % 1)
this.addError(path, "numberMaxDecimal", [schema.maxDecimal]);
};

Powered by Google App Engine
This is Rietveld 408576698