Update binary glTF header check(Reading binary glTF is still in progress)

This commit is contained in:
Syoyo Fujita 2017-05-30 01:21:36 +09:00
parent d7ec19c3dc
commit 40c4a0a60a

View File

@ -917,6 +917,10 @@ static bool LoadExternalFile(std::vector<unsigned char> *out, std::string *err,
f.seekg(0, f.end); f.seekg(0, f.end);
size_t sz = static_cast<size_t>(f.tellg()); size_t sz = static_cast<size_t>(f.tellg());
if (int(sz) < 0) {
// Looks reading directory, not a file.
return false;
}
std::vector<unsigned char> buf(sz); std::vector<unsigned char> buf(sz);
f.seekg(0, f.beg); f.seekg(0, f.beg);
@ -1430,7 +1434,7 @@ static bool ParseImage(Image *image, std::string *err,
isEmbedded = isEmbedded && static_cast<int>(bufferView) != -1; isEmbedded = isEmbedded && static_cast<int>(bufferView) != -1;
std::string uri; std::string uri;
if (!ParseStringProperty(&uri, err, o, "uri", true) && !isEmbedded) { if (!ParseStringProperty(&uri, err, o, "uri", true, "Image") && !isEmbedded) {
if (err) { if (err) {
(*err) += "Invalid image data (required data is missing).\n"; (*err) += "Invalid image data (required data is missing).\n";
} }
@ -1550,14 +1554,12 @@ static bool ParseBuffer(Buffer *buffer, std::string *err,
const unsigned char *bin_data = NULL, const unsigned char *bin_data = NULL,
size_t bin_size = 0) { size_t bin_size = 0) {
double byteLength; double byteLength;
if (!ParseNumberProperty(&byteLength, err, o, "byteLength", true)) { if (!ParseNumberProperty(&byteLength, err, o, "byteLength", true, "Buffer")) {
return false; return false;
} }
std::string uri; std::string uri;
if (!ParseStringProperty(&uri, err, o, "uri", true)) { ParseStringProperty(&uri, err, o, "uri", false, "Buffer");
return false;
}
picojson::object::const_iterator type = o.find("type"); picojson::object::const_iterator type = o.find("type");
if (type != o.end()) { if (type != o.end()) {
@ -1585,7 +1587,7 @@ static bool ParseBuffer(Buffer *buffer, std::string *err,
if ((bin_size == 0) || (bin_data == NULL)) { if ((bin_size == 0) || (bin_data == NULL)) {
if (err) { if (err) {
(*err) += "Invalid binary data.\n"; (*err) += "Invalid binary data in `Buffer'.\n";
} }
return false; return false;
} }
@ -1609,7 +1611,7 @@ static bool ParseBuffer(Buffer *buffer, std::string *err,
} else { } else {
if (err) { if (err) {
(*err) += "Invalid URI for binary data.\n"; (*err) += "Invalid URI for binary data in `Buffer'.\n";
} }
return false; return false;
} }
@ -1619,7 +1621,7 @@ static bool ParseBuffer(Buffer *buffer, std::string *err,
if (IsDataURI(uri)) { if (IsDataURI(uri)) {
if (!DecodeDataURI(&buffer->data, uri, bytes, true)) { if (!DecodeDataURI(&buffer->data, uri, bytes, true)) {
if (err) { if (err) {
(*err) += "Failed to decode 'uri'.\n"; (*err) += "Failed to decode 'uri' : " + uri + "\n";
} }
return false; return false;
} }
@ -2557,7 +2559,7 @@ bool TinyGLTFLoader::LoadBinaryFromMemory(Model *model, std::string *err,
swap4(&model_format); swap4(&model_format);
if ((20 + model_length >= size) || (model_length < 1) || if ((20 + model_length >= size) || (model_length < 1) ||
(model_format != 0)) { // 0 = JSON format. (model_format != 0x4E4F534A)) { // 0x4E4F534A = JSON format.
if (err) { if (err) {
(*err) = "Invalid glTF binary."; (*err) = "Invalid glTF binary.";
} }