2626// THE SOFTWARE.
2727
2828// Version:
29+ // - v2.6.0 Disable expanding file path for security(no use of awkward `wordexp` anymore).
2930// - v2.5.0 Add SetPreserveImageChannels() option to load image data as is.
3031// - v2.4.3 Fix null object output when when material has all default
3132// parameters.
@@ -108,7 +109,11 @@ namespace tinygltf {
108109#define TINYGLTF_COMPONENT_TYPE_INT (5124 )
109110#define TINYGLTF_COMPONENT_TYPE_UNSIGNED_INT (5125 )
110111#define TINYGLTF_COMPONENT_TYPE_FLOAT (5126 )
111- #define TINYGLTF_COMPONENT_TYPE_DOUBLE (5130 ) // OpenGL double type. Note that some of glTF 2.0 validator does not support double type even the schema seems allow any value of integer: https://github.com/KhronosGroup/glTF/blob/b9884a2fd45130b4d673dd6c8a706ee21ee5c5f7/specification/2.0/schema/accessor.schema.json#L22
112+ #define TINYGLTF_COMPONENT_TYPE_DOUBLE \
113+ (5130 ) // OpenGL double type. Note that some of glTF 2.0 validator does not
114+ // support double type even the schema seems allow any value of
115+ // integer:
116+ // https://github.com/KhronosGroup/glTF/blob/b9884a2fd45130b4d673dd6c8a706ee21ee5c5f7/specification/2.0/schema/accessor.schema.json#L22
112117
113118#define TINYGLTF_TEXTURE_FILTER_NEAREST (9728 )
114119#define TINYGLTF_TEXTURE_FILTER_LINEAR (9729 )
@@ -613,7 +618,8 @@ struct Sampler {
613618 int wrapT =
614619 TINYGLTF_TEXTURE_WRAP_REPEAT; // ["CLAMP_TO_EDGE", "MIRRORED_REPEAT",
615620 // "REPEAT"], default "REPEAT"
616- // int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT; // TinyGLTF extension. currently not used.
621+ // int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT; // TinyGLTF extension. currently
622+ // not used.
617623
618624 Value extras;
619625 ExtensionMap extensions;
@@ -1302,8 +1308,10 @@ class TinyGLTF {
13021308 // /
13031309 // / Loads glTF ASCII asset from string(memory).
13041310 // / `length` = strlen(str);
1305- // / Set warning message to `warn` for example it fails to load asserts.
1306- // / Returns false and set error string to `err` if there's an error.
1311+ // / `base_dir` is a search path of glTF asset(e.g. images). Path Must be an
1312+ // / expanded path (e.g. no tilde(`~`), no environment variables). Set warning
1313+ // / message to `warn` for example it fails to load asserts. Returns false and
1314+ // / set error string to `err` if there's an error.
13071315 // /
13081316 bool LoadASCIIFromString (Model *model, std::string *err, std::string *warn,
13091317 const char *str, const unsigned int length,
@@ -1322,6 +1330,8 @@ class TinyGLTF {
13221330 // /
13231331 // / Loads glTF binary asset from memory.
13241332 // / `length` = strlen(str);
1333+ // / `base_dir` is a search path of glTF asset(e.g. images). Path Must be an
1334+ // / expanded path (e.g. no tilde(`~`), no environment variables).
13251335 // / Set warning message to `warn` for example it fails to load asserts.
13261336 // / Returns false and set error string to `err` if there's an error.
13271337 // /
@@ -1605,7 +1615,7 @@ class TinyGLTF {
16051615#endif
16061616
16071617#elif !defined(__ANDROID__) && !defined(__OpenBSD__)
1608- #include < wordexp.h>
1618+ // #include <wordexp.h>
16091619#endif
16101620
16111621#if defined(__sparcv9) || defined(__powerpc__)
@@ -1933,10 +1943,9 @@ bool Sampler::operator==(const Sampler &other) const {
19331943 return this ->extensions == other.extensions && this ->extras == other.extras &&
19341944 this ->magFilter == other.magFilter &&
19351945 this ->minFilter == other.minFilter && this ->name == other.name &&
1936- this ->wrapS == other.wrapS &&
1937- this ->wrapT == other.wrapT ;
1946+ this ->wrapS == other.wrapS && this ->wrapT == other.wrapT ;
19381947
1939- // this->wrapR == other.wrapR
1948+ // this->wrapR == other.wrapR
19401949}
19411950bool Scene::operator ==(const Scene &other) const {
19421951 return this ->extensions == other.extensions && this ->extras == other.extras &&
@@ -2042,8 +2051,7 @@ static std::string GetBaseDir(const std::string &filepath) {
20422051
20432052static std::string GetBaseFilename (const std::string &filepath) {
20442053 auto idx = filepath.find_last_of (" /\\ " );
2045- if (idx != std::string::npos)
2046- return filepath.substr (idx + 1 );
2054+ if (idx != std::string::npos) return filepath.substr (idx + 1 );
20472055 return filepath;
20482056}
20492057
@@ -2605,6 +2613,18 @@ bool FileExists(const std::string &abs_filename, void *) {
26052613}
26062614
26072615std::string ExpandFilePath (const std::string &filepath, void *) {
2616+ // https://github.com/syoyo/tinygltf/issues/368
2617+ //
2618+ // No file path expansion in built-in FS function anymore, since glTF URI
2619+ // should not contain tilde('~') and environment variables, and for security
2620+ // reason(`wordexp`).
2621+ //
2622+ // Users need to supply `base_dir`(in `LoadASCIIFromString`,
2623+ // `LoadBinaryFromMemory`) in expanded absolute path.
2624+
2625+ return filepath;
2626+
2627+ #if 0
26082628#ifdef _WIN32
26092629 // Assume input `filepath` is encoded in UTF-8
26102630 std::wstring wfilepath = UTF8ToWchar(filepath);
@@ -2652,6 +2672,7 @@ std::string ExpandFilePath(const std::string &filepath, void *) {
26522672
26532673 return s;
26542674#endif
2675+ #endif
26552676}
26562677
26572678bool ReadWholeFile (std::vector<unsigned char > *out, std::string *err,
@@ -4242,20 +4263,20 @@ static bool ParseSparseAccessor(Accessor *accessor, std::string *err,
42424263 const json &values_obj = GetValue (values_iterator);
42434264
42444265 int indices_buffer_view = 0 , indices_byte_offset = 0 , component_type = 0 ;
4245- if (!ParseIntegerProperty (&indices_buffer_view, err, indices_obj, " bufferView " ,
4246- true , " SparseAccessor" )) {
4266+ if (!ParseIntegerProperty (&indices_buffer_view, err, indices_obj,
4267+ " bufferView " , true , " SparseAccessor" )) {
42474268 return false ;
42484269 }
42494270 ParseIntegerProperty (&indices_byte_offset, err, indices_obj, " byteOffset" ,
42504271 false );
42514272 if (!ParseIntegerProperty (&component_type, err, indices_obj, " componentType" ,
4252- true , " SparseAccessor" )) {
4273+ true , " SparseAccessor" )) {
42534274 return false ;
42544275 }
42554276
42564277 int values_buffer_view = 0 , values_byte_offset = 0 ;
42574278 if (!ParseIntegerProperty (&values_buffer_view, err, values_obj, " bufferView" ,
4258- true , " SparseAccessor" )) {
4279+ true , " SparseAccessor" )) {
42594280 return false ;
42604281 }
42614282 ParseIntegerProperty (&values_byte_offset, err, values_obj, " byteOffset" ,
@@ -5094,12 +5115,13 @@ static bool ParseSampler(Sampler *sampler, std::string *err, const json &o,
50945115 int magFilter = -1 ;
50955116 int wrapS = TINYGLTF_TEXTURE_WRAP_REPEAT;
50965117 int wrapT = TINYGLTF_TEXTURE_WRAP_REPEAT;
5097- // int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT;
5118+ // int wrapR = TINYGLTF_TEXTURE_WRAP_REPEAT;
50985119 ParseIntegerProperty (&minFilter, err, o, " minFilter" , false );
50995120 ParseIntegerProperty (&magFilter, err, o, " magFilter" , false );
51005121 ParseIntegerProperty (&wrapS, err, o, " wrapS" , false );
51015122 ParseIntegerProperty (&wrapT, err, o, " wrapT" , false );
5102- // ParseIntegerProperty(&wrapR, err, o, "wrapR", false); // tinygltf extension
5123+ // ParseIntegerProperty(&wrapR, err, o, "wrapR", false); // tinygltf
5124+ // extension
51035125
51045126 // TODO(syoyo): Check the value is alloed one.
51055127 // (e.g. we allow 9728(NEAREST), but don't allow 9727)
@@ -5108,7 +5130,7 @@ static bool ParseSampler(Sampler *sampler, std::string *err, const json &o,
51085130 sampler->magFilter = magFilter;
51095131 sampler->wrapS = wrapS;
51105132 sampler->wrapT = wrapT;
5111- // sampler->wrapR = wrapR;
5133+ // sampler->wrapR = wrapR;
51125134
51135135 ParseExtensionsProperty (&(sampler->extensions ), err, o);
51145136 ParseExtrasProperty (&(sampler->extras ), o);
@@ -7171,7 +7193,7 @@ static void SerializeGltfSampler(Sampler &sampler, json &o) {
71717193 if (sampler.minFilter != -1 ) {
71727194 SerializeNumberProperty (" minFilter" , sampler.minFilter , o);
71737195 }
7174- // SerializeNumberProperty("wrapR", sampler.wrapR, o);
7196+ // SerializeNumberProperty("wrapR", sampler.wrapR, o);
71757197 SerializeNumberProperty (" wrapS" , sampler.wrapS , o);
71767198 SerializeNumberProperty (" wrapT" , sampler.wrapT , o);
71777199
@@ -7534,8 +7556,10 @@ static void WriteBinaryGltfStream(std::ostream &stream,
75347556 const uint32_t content_size = uint32_t (content.size ());
75357557 const uint32_t binBuffer_size = uint32_t (binBuffer.size ());
75367558 // determine number of padding bytes required to ensure 4 byte alignment
7537- const uint32_t content_padding_size = content_size % 4 == 0 ? 0 : 4 - content_size % 4 ;
7538- const uint32_t bin_padding_size = binBuffer_size % 4 == 0 ? 0 : 4 - binBuffer_size % 4 ;
7559+ const uint32_t content_padding_size =
7560+ content_size % 4 == 0 ? 0 : 4 - content_size % 4 ;
7561+ const uint32_t bin_padding_size =
7562+ binBuffer_size % 4 == 0 ? 0 : 4 - binBuffer_size % 4 ;
75397563
75407564 // 12 bytes for header, JSON content length, 8 bytes for JSON chunk info.
75417565 // Chunk data must be located at 4-byte boundary, which may require padding
0 commit comments