Skip to content
12 changes: 11 additions & 1 deletion src/OpenColorIO/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vector>
#include <regex>
#include <functional>
#include <filesystem>

#include <pystring.h>

Expand Down Expand Up @@ -1153,9 +1154,10 @@ ConstConfigRcPtr Config::CreateFromEnv()

ConstConfigRcPtr Config::CreateFromFile(const char * filename)
{
// Specifically check if a config filepath is provided.
if (!filename || !*filename)
{
throw ExceptionMissingFile ("The config filepath is missing.");
throw Exception("The config filepath is missing.");
}

// Check for URI Pattern: ocio://<config name>
Expand All @@ -1167,6 +1169,14 @@ ConstConfigRcPtr Config::CreateFromFile(const char * filename)
return CreateFromBuiltinConfig(uri.c_str());
}

// Specifically check if the provided non-builtin config filepath exists.
if (!std::filesystem::exists(filename))
{
std::ostringstream oss;
oss << "'" << filename << "' file does not exist.";
throw ExceptionMissingFile(oss.str().c_str());
}

std::ifstream ifstream = Platform::CreateInputFileStream(
filename,
std::ios_base::in | std::ios_base::binary
Expand Down
4 changes: 2 additions & 2 deletions tests/cpu/builtinconfigs/BuiltinConfig_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ OCIO_ADD_TEST(BuiltinConfigs, create_builtin_config)
// Test that CreateFromFile does not work without ocio:// prefix for built-in config.
OCIO_CHECK_THROW_WHAT(
OCIO::Config::CreateFromFile("cg-config-v1.0.0_aces-v1.3_ocio-v2.1"),
OCIO::Exception,
"Error could not read 'cg-config-v1.0.0_aces-v1.3_ocio-v2.1' OCIO profile."
OCIO::ExceptionMissingFile,
"'cg-config-v1.0.0_aces-v1.3_ocio-v2.1' file does not exist."
);

{
Expand Down
2 changes: 1 addition & 1 deletion tests/python/ConfigTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ def testFromEnvAndFromFile(uri, numberOfExpectedColorspaces, expectedConfigName)
nbOfColorspacesForStudioConfig = 55

# Test that CreateFromFile does not work without ocio:// prefix for built-in config.
with self.assertRaises(OCIO.Exception) as cm:
with self.assertRaises(OCIO.ExceptionMissingFile) as cm:
OCIO.Config.CreateFromFile(cgConfigName)

# Test CG config.
Expand Down