From 0b3e731f0b40c5a0b2fa5b0bfd6f25f87279c5cc Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 21 Aug 2017 10:44:04 -0700 Subject: [PATCH] Add better diagnostics for NaN or Infinity in input JSON --- CHANGELOG.md | 4 ++++ jsonpull/jsonpull.c | 30 ++++++++++++++++++++++++++++-- version.hpp | 2 +- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba178ee..10f6f86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.22.2 + +* Add better diagnostics for NaN or Infinity in input JSON + ## 1.22.1 * Fix tilestats generation when long string attribute values are elided diff --git a/jsonpull/jsonpull.c b/jsonpull/jsonpull.c index d50df43..ad4d152 100644 --- a/jsonpull/jsonpull.c +++ b/jsonpull/jsonpull.c @@ -400,6 +400,32 @@ again: return add_object(j, JSON_NULL); } + /////////////////////////// NaN + + if (c == 'N') { + if (read_wrap(j) != 'a' || read_wrap(j) != 'N') { + j->error = "Found misspelling of NaN"; + return NULL; + } + + j->error = "JSON does not allow NaN"; + return NULL; + } + + /////////////////////////// Infinity + + if (c == 'I') { + if (read_wrap(j) != 'n' || read_wrap(j) != 'f' || read_wrap(j) != 'i' || + read_wrap(j) != 'n' || read_wrap(j) != 'i' || read_wrap(j) != 't' || + read_wrap(j) != 'y') { + j->error = "Found misspelling of Infinity"; + return NULL; + } + + j->error = "JSON does not allow Infinity"; + return NULL; + } + /////////////////////////// True if (c == 't') { @@ -740,7 +766,7 @@ void json_disconnect(json_object *o) { static void json_print_one(struct string *val, json_object *o) { if (o == NULL) { - string_append_string(val, "NULL"); + string_append_string(val, "..."); } else if (o->type == JSON_STRING) { string_append(val, '\"'); @@ -779,7 +805,7 @@ static void json_print_one(struct string *val, json_object *o) { static void json_print(struct string *val, json_object *o) { if (o == NULL) { // Hash value in incompletely read hash - string_append_string(val, "NULL"); + string_append_string(val, "..."); } else if (o->type == JSON_HASH) { string_append(val, '{'); diff --git a/version.hpp b/version.hpp index 086f04b..4969b94 100644 --- a/version.hpp +++ b/version.hpp @@ -1,6 +1,6 @@ #ifndef VERSION_HPP #define VERSION_HPP -#define VERSION "tippecanoe v1.22.1\n" +#define VERSION "tippecanoe v1.22.2\n" #endif