]> granicus.if.org Git - json-c/commitdiff
Fix double to int cast overflow in json_object_get_int64.
authorKurt Schwehr <schwehr@google.com>
Mon, 11 Sep 2017 14:23:00 +0000 (07:23 -0700)
committerKurt Schwehr <schwehr@google.com>
Mon, 11 Sep 2017 14:23:00 +0000 (07:23 -0700)
Found with autofuzz in GDAL

json_object.c

index 9ffb149d07b50425aadaacf0f2008a56b6aca7a0..8cd5922e349f0d9cf4536d4ada6bd67991635f56 100644 (file)
@@ -688,6 +688,10 @@ int64_t json_object_get_int64(const struct json_object *jso)
        case json_type_int:
                return jso->o.c_int64;
        case json_type_double:
+               if (jso->o.c_double >= INT64_MAX)
+                       return INT64_MAX;
+               if (jso->o.c_double <= INT64_MIN)
+                       return INT64_MIN;
                return (int64_t)jso->o.c_double;
        case json_type_boolean:
                return jso->o.c_boolean;