mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-08-15 14:55:55 +08:00
Check if JSON element is valid JSON object or not. Now all fuzz input passes. Fixes #16.
This commit is contained in:
parent
cdf849061c
commit
59130d1a19
77
tiny_gltf.h
77
tiny_gltf.h
@ -2401,6 +2401,12 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
picojson::array::const_iterator it(root.begin());
|
picojson::array::const_iterator it(root.begin());
|
||||||
picojson::array::const_iterator itEnd(root.end());
|
picojson::array::const_iterator itEnd(root.end());
|
||||||
for (; it != itEnd; it++) {
|
for (; it != itEnd; it++) {
|
||||||
|
if (!it->is<picojson::object>()) {
|
||||||
|
if (err) {
|
||||||
|
(*err) += "`buffers' does not contain an JSON object.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Buffer buffer;
|
Buffer buffer;
|
||||||
if (!ParseBuffer(&buffer, err, it->get<picojson::object>(), base_dir,
|
if (!ParseBuffer(&buffer, err, it->get<picojson::object>(), base_dir,
|
||||||
is_binary_, bin_data_, bin_size_)) {
|
is_binary_, bin_data_, bin_size_)) {
|
||||||
@ -2418,6 +2424,12 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
picojson::array::const_iterator it(root.begin());
|
picojson::array::const_iterator it(root.begin());
|
||||||
picojson::array::const_iterator itEnd(root.end());
|
picojson::array::const_iterator itEnd(root.end());
|
||||||
for (; it != itEnd; it++) {
|
for (; it != itEnd; it++) {
|
||||||
|
if (!it->is<picojson::object>()) {
|
||||||
|
if (err) {
|
||||||
|
(*err) += "`bufferViews' does not contain an JSON object.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
BufferView bufferView;
|
BufferView bufferView;
|
||||||
if (!ParseBufferView(&bufferView, err, it->get<picojson::object>())) {
|
if (!ParseBufferView(&bufferView, err, it->get<picojson::object>())) {
|
||||||
return false;
|
return false;
|
||||||
@ -2434,6 +2446,12 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
picojson::array::const_iterator it(root.begin());
|
picojson::array::const_iterator it(root.begin());
|
||||||
picojson::array::const_iterator itEnd(root.end());
|
picojson::array::const_iterator itEnd(root.end());
|
||||||
for (; it != itEnd; it++) {
|
for (; it != itEnd; it++) {
|
||||||
|
if (!it->is<picojson::object>()) {
|
||||||
|
if (err) {
|
||||||
|
(*err) += "`accessors' does not contain an JSON object.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Accessor accessor;
|
Accessor accessor;
|
||||||
if (!ParseAccessor(&accessor, err, it->get<picojson::object>())) {
|
if (!ParseAccessor(&accessor, err, it->get<picojson::object>())) {
|
||||||
return false;
|
return false;
|
||||||
@ -2450,6 +2468,12 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
picojson::array::const_iterator it(root.begin());
|
picojson::array::const_iterator it(root.begin());
|
||||||
picojson::array::const_iterator itEnd(root.end());
|
picojson::array::const_iterator itEnd(root.end());
|
||||||
for (; it != itEnd; it++) {
|
for (; it != itEnd; it++) {
|
||||||
|
if (!it->is<picojson::object>()) {
|
||||||
|
if (err) {
|
||||||
|
(*err) += "`meshes' does not contain an JSON object.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Mesh mesh;
|
Mesh mesh;
|
||||||
if (!ParseMesh(&mesh, err, it->get<picojson::object>())) {
|
if (!ParseMesh(&mesh, err, it->get<picojson::object>())) {
|
||||||
return false;
|
return false;
|
||||||
@ -2466,6 +2490,12 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
picojson::array::const_iterator it(root.begin());
|
picojson::array::const_iterator it(root.begin());
|
||||||
picojson::array::const_iterator itEnd(root.end());
|
picojson::array::const_iterator itEnd(root.end());
|
||||||
for (; it != itEnd; it++) {
|
for (; it != itEnd; it++) {
|
||||||
|
if (!it->is<picojson::object>()) {
|
||||||
|
if (err) {
|
||||||
|
(*err) += "`nodes' does not contain an JSON object.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Node node;
|
Node node;
|
||||||
if (!ParseNode(&node, err, it->get<picojson::object>())) {
|
if (!ParseNode(&node, err, it->get<picojson::object>())) {
|
||||||
return false;
|
return false;
|
||||||
@ -2484,7 +2514,7 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
for (; it != itEnd; it++) {
|
for (; it != itEnd; it++) {
|
||||||
if (!(it->is<picojson::object>())) {
|
if (!(it->is<picojson::object>())) {
|
||||||
if (err) {
|
if (err) {
|
||||||
(*err) += "`scenes' does not contain an object.";
|
(*err) += "`scenes' does not contain an JSON object.";
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2519,6 +2549,12 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
picojson::array::const_iterator it(root.begin());
|
picojson::array::const_iterator it(root.begin());
|
||||||
picojson::array::const_iterator itEnd(root.end());
|
picojson::array::const_iterator itEnd(root.end());
|
||||||
for (; it != itEnd; it++) {
|
for (; it != itEnd; it++) {
|
||||||
|
if (!it->is<picojson::object>()) {
|
||||||
|
if (err) {
|
||||||
|
(*err) += "`materials' does not contain an JSON object.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
picojson::object jsonMaterial = it->get<picojson::object>();
|
picojson::object jsonMaterial = it->get<picojson::object>();
|
||||||
|
|
||||||
Material material;
|
Material material;
|
||||||
@ -2539,6 +2575,12 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
picojson::array::const_iterator it(root.begin());
|
picojson::array::const_iterator it(root.begin());
|
||||||
picojson::array::const_iterator itEnd(root.end());
|
picojson::array::const_iterator itEnd(root.end());
|
||||||
for (; it != itEnd; it++) {
|
for (; it != itEnd; it++) {
|
||||||
|
if (!it->is<picojson::object>()) {
|
||||||
|
if (err) {
|
||||||
|
(*err) += "`images' does not contain an JSON object.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Image image;
|
Image image;
|
||||||
if (!ParseImage(&image, err, it->get<picojson::object>(), base_dir,
|
if (!ParseImage(&image, err, it->get<picojson::object>(), base_dir,
|
||||||
is_binary_, bin_data_, bin_size_)) {
|
is_binary_, bin_data_, bin_size_)) {
|
||||||
@ -2580,6 +2622,12 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
picojson::array::const_iterator it(root.begin());
|
picojson::array::const_iterator it(root.begin());
|
||||||
picojson::array::const_iterator itEnd(root.end());
|
picojson::array::const_iterator itEnd(root.end());
|
||||||
for (; it != itEnd; it++) {
|
for (; it != itEnd; it++) {
|
||||||
|
if (!it->is<picojson::object>()) {
|
||||||
|
if (err) {
|
||||||
|
(*err) += "`textures' does not contain an JSON object.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Texture texture;
|
Texture texture;
|
||||||
if (!ParseTexture(&texture, err, it->get<picojson::object>(), base_dir)) {
|
if (!ParseTexture(&texture, err, it->get<picojson::object>(), base_dir)) {
|
||||||
return false;
|
return false;
|
||||||
@ -2596,6 +2644,12 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
picojson::array::const_iterator it(root.begin());
|
picojson::array::const_iterator it(root.begin());
|
||||||
picojson::array::const_iterator itEnd(root.end());
|
picojson::array::const_iterator itEnd(root.end());
|
||||||
for (; it != itEnd; ++it) {
|
for (; it != itEnd; ++it) {
|
||||||
|
if (!it->is<picojson::object>()) {
|
||||||
|
if (err) {
|
||||||
|
(*err) += "`animations' does not contain an JSON object.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Animation animation;
|
Animation animation;
|
||||||
if (!ParseAnimation(&animation, err, it->get<picojson::object>())) {
|
if (!ParseAnimation(&animation, err, it->get<picojson::object>())) {
|
||||||
return false;
|
return false;
|
||||||
@ -2612,6 +2666,12 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
picojson::array::const_iterator it(root.begin());
|
picojson::array::const_iterator it(root.begin());
|
||||||
picojson::array::const_iterator itEnd(root.end());
|
picojson::array::const_iterator itEnd(root.end());
|
||||||
for (; it != itEnd; ++it) {
|
for (; it != itEnd; ++it) {
|
||||||
|
if (!it->is<picojson::object>()) {
|
||||||
|
if (err) {
|
||||||
|
(*err) += "`skins' does not contain an JSON object.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Skin skin;
|
Skin skin;
|
||||||
if (!ParseSkin(&skin, err, it->get<picojson::object>())) {
|
if (!ParseSkin(&skin, err, it->get<picojson::object>())) {
|
||||||
return false;
|
return false;
|
||||||
@ -2628,10 +2688,13 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
picojson::array::const_iterator it(root.begin());
|
picojson::array::const_iterator it(root.begin());
|
||||||
picojson::array::const_iterator itEnd(root.end());
|
picojson::array::const_iterator itEnd(root.end());
|
||||||
for (; it != itEnd; ++it) {
|
for (; it != itEnd; ++it) {
|
||||||
Sampler sampler;
|
if (!it->is<picojson::object>()) {
|
||||||
if (!(it->is<picojson::object>())) {
|
if (err) {
|
||||||
continue;
|
(*err) += "`samplers' does not contain an JSON object.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
Sampler sampler;
|
||||||
if (!ParseSampler(&sampler, err, it->get<picojson::object>())) {
|
if (!ParseSampler(&sampler, err, it->get<picojson::object>())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -2647,6 +2710,12 @@ bool TinyGLTF::LoadFromString(Model *model, std::string *err, const char *str,
|
|||||||
picojson::array::const_iterator it(root.begin());
|
picojson::array::const_iterator it(root.begin());
|
||||||
picojson::array::const_iterator itEnd(root.end());
|
picojson::array::const_iterator itEnd(root.end());
|
||||||
for (; it != itEnd; ++it) {
|
for (; it != itEnd; ++it) {
|
||||||
|
if (!it->is<picojson::object>()) {
|
||||||
|
if (err) {
|
||||||
|
(*err) += "`cameras' does not contain an JSON object.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Camera camera;
|
Camera camera;
|
||||||
if (!ParseCamera(&camera, err, it->get<picojson::object>())) {
|
if (!ParseCamera(&camera, err, it->get<picojson::object>())) {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user