- Path has to have length under 256 character.
- Coverity issue fix
Change-Id: I1fd185e4b1174201736d38bf8751ec9f806cd04b
Signed-off-by: Seungho, Baek <sbsh.baek@samsung.com>
* limitations under the License.
*
*/
* limitations under the License.
*
*/
// CLASS HEADER
#include <dali-toolkit/internal/controls/scene/gltf-loader.h>
#include <dali-toolkit/internal/controls/scene/gltf-shader.h>
// CLASS HEADER
#include <dali-toolkit/internal/controls/scene/gltf-loader.h>
#include <dali-toolkit/internal/controls/scene/gltf-shader.h>
+namespace
+{
+
+// Maximum path length of linux.
+const unsigned int MAX_PATH_LENGTH = 4096;
+
+}//namespace
+
GltfLoader::GltfLoader()
: mNodes( NULL ),
mRoot( NULL )
GltfLoader::GltfLoader()
: mNodes( NULL ),
mRoot( NULL )
}
mRoot = mParser.GetRoot();
}
mRoot = mParser.GetRoot();
- if( !mRoot )
- {
- return false;
- }
-
- if( !LoadAssets() )
+ if( mRoot &&
+ LoadAssets() &&
+ CreateScene( scene ) )
- return false;
- }
-
- if( !CreateScene( scene ) )
- {
- return false;
}
bool GltfLoader::ParseGltf( const std::string& filePath )
{
}
bool GltfLoader::ParseGltf( const std::string& filePath )
{
+ if( filePath.length() > MAX_PATH_LENGTH )
+ {
+ DALI_LOG_ERROR( "File path is too long.\n" );
+ return false;
+ }
std::ifstream fileStream( filePath.c_str() );
std::string fileBuffer( ( std::istreambuf_iterator<char>( fileStream ) ),
( std::istreambuf_iterator<char>() ) );
std::ifstream fileStream( filePath.c_str() );
std::string fileBuffer( ( std::istreambuf_iterator<char>( fileStream ) ),
( std::istreambuf_iterator<char>() ) );
bool GltfLoader::LoadAssets()
{
bool GltfLoader::LoadAssets()
{
- if( LoadBinaryData( mRoot ) && // pass a reference
- LoadTextureArray( mRoot ) && // pass a reference
- LoadMaterialSetArray( mRoot ) && // pass a reference
- LoadMeshArray( mRoot ) // pass a reference
+ if( LoadBinaryData( mRoot ) &&
+ LoadTextureArray( mRoot ) &&
+ LoadMaterialSetArray( mRoot ) &&
+ LoadMeshArray( mRoot )
Texture GltfLoader::LoadTexture( const char* imageUrl, bool generateMipmaps )
{
Texture texture;
Texture GltfLoader::LoadTexture( const char* imageUrl, bool generateMipmaps )
{
Texture texture;
+ if( std::string( imageUrl ).length() > MAX_PATH_LENGTH )
+ {
+ DALI_LOG_ERROR( "Image path is too long.\n" );
+ return texture;
+ }
Devel::PixelBuffer pixelBuffer = LoadImageFromFile( imageUrl );
if( pixelBuffer )
{
texture = Texture::New( TextureType::TEXTURE_2D, pixelBuffer.GetPixelFormat(), pixelBuffer.GetWidth(), pixelBuffer.GetHeight() );
PixelData pixelData = Devel::PixelBuffer::Convert( pixelBuffer );
texture.Upload( pixelData );
Devel::PixelBuffer pixelBuffer = LoadImageFromFile( imageUrl );
if( pixelBuffer )
{
texture = Texture::New( TextureType::TEXTURE_2D, pixelBuffer.GetPixelFormat(), pixelBuffer.GetWidth(), pixelBuffer.GetHeight() );
PixelData pixelData = Devel::PixelBuffer::Convert( pixelBuffer );
texture.Upload( pixelData );
if( generateMipmaps )
{
texture.GenerateMipmaps();
if( generateMipmaps )
{
texture.GenerateMipmaps();
if( ( tempNode = node->GetChild( "mesh" ) ) )
{
MeshInfo meshInfo = mMeshArray[tempNode->GetInteger()];
if( ( tempNode = node->GetChild( "mesh" ) ) )
{
MeshInfo meshInfo = mMeshArray[tempNode->GetInteger()];
- GLTF::MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx];
bool isMaterial = ( meshInfo.materialsIdx >= 0 );
TextureSet textureSet;
bool isMaterial = ( meshInfo.materialsIdx >= 0 );
TextureSet textureSet;
bool useIBL = ( scene.GetLightType() >= Toolkit::Scene::LightType::IMAGE_BASED_LIGHT );
if( isMaterial )
{
bool useIBL = ( scene.GetLightType() >= Toolkit::Scene::LightType::IMAGE_BASED_LIGHT );
if( isMaterial )
{
+ GLTF::MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx];
if( SetTextureAndSampler( textureSet, materialInfo.baseColorTexture.index, FRAGMENT_SHADER, DEFINE_BASECOLOR_TEXTURE, addIdx ) )
{
shaderTypeIndex += static_cast<int>( ShaderType::BASECOLOR_SHADER );
if( SetTextureAndSampler( textureSet, materialInfo.baseColorTexture.index, FRAGMENT_SHADER, DEFINE_BASECOLOR_TEXTURE, addIdx ) )
{
shaderTypeIndex += static_cast<int>( ShaderType::BASECOLOR_SHADER );
actor.RegisterProperty( "uIsColor", meshInfo.attribute.COLOR.size() > 0 );
if( isMaterial )
{
actor.RegisterProperty( "uIsColor", meshInfo.attribute.COLOR.size() > 0 );
if( isMaterial )
{
+ GLTF::MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx];
actor.RegisterProperty( "uBaseColorFactor", materialInfo.baseColorFactor );
actor.RegisterProperty( "uMetallicRoughnessFactors", Vector2( materialInfo.metallicFactor, materialInfo.roughnessFactor ) );
actor.RegisterProperty( "uBaseColorFactor", materialInfo.baseColorFactor );
actor.RegisterProperty( "uMetallicRoughnessFactors", Vector2( materialInfo.metallicFactor, materialInfo.roughnessFactor ) );
template <typename T>
bool GltfLoader::ReadBinFile( Vector<T> &dataBuffer, std::string url, int offset, int count )
{
template <typename T>
bool GltfLoader::ReadBinFile( Vector<T> &dataBuffer, std::string url, int offset, int count )
{
+ if( url.length() > MAX_PATH_LENGTH )
+ {
+ DALI_LOG_ERROR( "Binary file path is too long.\n" );
+ return false;
+ }
dataBuffer.Resize( count );
FILE* fp = fopen( url.c_str(), "rb" );
dataBuffer.Resize( count );
FILE* fp = fopen( url.c_str(), "rb" );
- fseek( fp, offset, SEEK_SET );
- ssize_t result = fread( &dataBuffer[0], sizeof( T ), count, fp );
+ ssize_t result = -1;
+ if( !fseek( fp, offset, SEEK_SET ) )
+ {
+ result = fread( &dataBuffer[0], sizeof( T ), count, fp );
+ }
fclose( fp );
return ( result >= 0 );
fclose( fp );
return ( result >= 0 );
* limitations under the License.
*
*/
* limitations under the License.
*
*/
// CLASS HEADER
#include "scene-impl.h"
// CLASS HEADER
#include "scene-impl.h"
{
faceSize = imageWidth / 6;
}
{
faceSize = imageWidth / 6;
}
unsigned int xOffset = cubeMap_index_x[cubeType][faceIndex] * faceSize;
unsigned int yOffset = cubeMap_index_y[cubeType][faceIndex] * faceSize;
unsigned int xOffset = cubeMap_index_x[cubeType][faceIndex] * faceSize;
unsigned int yOffset = cubeMap_index_y[cubeType][faceIndex] * faceSize;