Skip to content

Commit

Permalink
Bugfix to account for single dot input.
Browse files Browse the repository at this point in the history
Signed-off-by: Mei Chu <[email protected]>
  • Loading branch information
meimchu committed Mar 31, 2024
1 parent 537431d commit 0763c37
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/OpenColorIO/transforms/FileTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,12 @@ bool FormatRegistry::isFormatExtensionSupported(const char * extension) const
{
FileFormatVectorMap::const_iterator iter;
// If dot is present at the start, pointer arithmetic increment up by one to ignore that dot.
if (extension[0] == '.')
// Early return false with malicious input of just the dot.
if (0 == strcmp(extension, "."))
{
return false;
}
else if (extension[0] == '.')
{
iter = m_formatsByExtension.find(StringUtils::Lower(extension + 1));
}
Expand Down
1 change: 1 addition & 0 deletions tests/cpu/transforms/FileTransform_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ OCIO_ADD_TEST(FileTransform, is_format_extension_supported)
OCIO::FormatRegistry & formatRegistry = OCIO::FormatRegistry::GetInstance();
OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported("foo"), false);
OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported("bar"), false);
OCIO_CHECK_EQUAL(formatRegistry.isFormatExtensionSupported("."), false);
OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("cdl"));
OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported(".cdl"));
OCIO_CHECK_ASSERT(formatRegistry.isFormatExtensionSupported("Cdl"));
Expand Down
1 change: 1 addition & 0 deletions tests/python/FileTransformTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def test_is_format_extension_supported(self):
"""
self.assertFalse(self.tr.IsFormatExtensionSupported('foo'))
self.assertFalse(self.tr.IsFormatExtensionSupported('bar'))
self.assertFalse(self.tr.IsFormatExtensionSupported('.'))
self.assertTrue(self.tr.IsFormatExtensionSupported('cdl'))
self.assertTrue(self.tr.IsFormatExtensionSupported('.cdl'))
self.assertTrue(self.tr.IsFormatExtensionSupported('Cdl'))
Expand Down

0 comments on commit 0763c37

Please sign in to comment.