From f7bd377a69ddd58fa5ad9bc690860b7ec43b7939 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Sat, 21 Mar 2026 05:36:13 +0900 Subject: [PATCH] Update tiny_gltf_v3.h Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- tiny_gltf_v3.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tiny_gltf_v3.h b/tiny_gltf_v3.h index 614b81a..931af22 100644 --- a/tiny_gltf_v3.h +++ b/tiny_gltf_v3.h @@ -1750,7 +1750,25 @@ static int tg3__parse_int(tg3__parse_ctx *ctx, const tg3__json &o, "Field '%s' must be a number", key); return 0; } - *out = it->get(); + if (it->is_number_integer()) { + int64_t v = it->get(); + if (v < (int64_t)INT32_MIN || v > (int64_t)INT32_MAX) { + tg3__error_pushf(ctx->errors, ctx->arena, TG3_SEVERITY_ERROR, + TG3_ERR_JSON_TYPE_MISMATCH, parent, + "Field '%s' value %" PRId64 " is out of range for int32", key, v); + return 0; + } + *out = (int32_t)v; + } else { + double d = it->get(); + if (d < (double)INT32_MIN || d > (double)INT32_MAX) { + tg3__error_pushf(ctx->errors, ctx->arena, TG3_SEVERITY_ERROR, + TG3_ERR_JSON_TYPE_MISMATCH, parent, + "Field '%s' value %f is out of range for int32", key, d); + return 0; + } + *out = (int32_t)d; + } return 1; }