Skip to content

Commit c173846

Browse files
authored
Adsk Contrib - Miscellaneous improvements suggested by Claude (#2308)
* Various fixes suggested by Claude Signed-off-by: Doug Walker <doug.walker@autodesk.com> * Address review comments Signed-off-by: Doug Walker <doug.walker@autodesk.com> * Update security guidelines Signed-off-by: Doug Walker <doug.walker@autodesk.com> * Address review comments Signed-off-by: Doug Walker <doug.walker@autodesk.com> * Further max Lut3D size cleanup Signed-off-by: Doug Walker <doug.walker@autodesk.com> * Improve cast to avoid possible warning Signed-off-by: Doug Walker <doug.walker@autodesk.com> --------- Signed-off-by: Doug Walker <doug.walker@autodesk.com>
1 parent 222ca50 commit c173846

64 files changed

Lines changed: 580 additions & 137 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

SECURITY.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,16 @@ would be naive to say our code is immune to every exploit.
1414

1515
## Reporting Vulnerabilities
1616

17-
Quickly resolving security related issues is a priority. If you think
18-
you've found a potential vulnerability in OpenColorIO, please report it by
19-
emailing security@opencolorio.org. Only TSC members and ASWF project
20-
management have access to these messages.
17+
Quickly resolving security related issues is a priority. The best way to report a
18+
vulnerability is to file a GitHub security advisory. If that is not possible, it
19+
is also fine to email your report to security@opencolorio.org. Only the project
20+
administrators have access to these reports.
2121

2222
Include detailed steps to reproduce the issue, and any other information that
2323
could aid an investigation. Someone will assess the report and make every
2424
effort to respond within 14 days.
2525

26-
## Outstanding Security Issues
27-
28-
None
29-
30-
## Addressed Security Issues
26+
## History of CVE Fixes
3127

3228
None
3329

@@ -64,6 +60,3 @@ set of behaviors as with file loading.
6460
It is a bug if calling a function with well-formed arguments causes the
6561
library to crash. It is a security issue if calling a function with
6662
well-formed arguments causes arbitrary code execution.
67-
68-
We do not consider this as severe as file format issues because in most
69-
deployments the parameter space is not exposed to potential attackers.

docs/site/homepage/config.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,6 @@ post_share = true
105105
enable = false
106106
preloader = "images/opencolorio-color.png"
107107

108-
# google map
109-
[params.map]
110-
enable = false
111-
gmap_api = "https://maps.googleapis.com/maps/api/js?key=AIzaSyBu5nZKbeK-WHQ70oqOWo-_4VmwOwKP9YQ"
112-
map_latitude = "51.5223477"
113-
map_longitude = "-0.1622023"
114-
map_marker = "images/marker.png"
115-
116108

117109
############################# ASWF LINKS ##########################
118110
[[params.aswf]]

ext/sampleicc/src/include/iccProfileReader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ namespace SampleICC
586586
if (!Read32(istream, &sizeData, 1))
587587
return false;
588588

589+
// ICC curve entries are indexed by 16-bit values; 65536 is the maximum.
590+
if (sizeData > 65536)
591+
return false;
592+
589593
mCurve.resize(sizeData);
590594

591595
if (sizeData)

src/OpenColorIO/ColorSpace.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ const char * ColorSpace::getAlias(size_t idx) const noexcept
162162

163163
bool ColorSpace::hasAlias(const char * alias) const noexcept
164164
{
165+
if (!alias) return false;
165166
for (size_t idx = 0; idx < getImpl()->m_aliases.size(); ++idx)
166167
{
167168
if (0 == Platform::Strcasecmp(getImpl()->m_aliases[idx].c_str(), alias))
@@ -430,6 +431,7 @@ int ColorSpace::getAllocationNumVars() const
430431

431432
void ColorSpace::getAllocationVars(float * vars) const
432433
{
434+
if(!vars) return;
433435
if(!getImpl()->m_allocationVars.empty())
434436
{
435437
memcpy(vars,
@@ -440,6 +442,15 @@ void ColorSpace::getAllocationVars(float * vars) const
440442

441443
void ColorSpace::setAllocationVars(int numvars, const float * vars)
442444
{
445+
if (numvars < 0)
446+
{
447+
throw Exception("setAllocationVars: numvars must not be negative.");
448+
}
449+
if (numvars > 0 && !vars)
450+
{
451+
throw Exception("setAllocationVars: vars must not be null when numvars is positive.");
452+
}
453+
443454
getImpl()->m_allocationVars.resize(numvars);
444455

445456
if(!getImpl()->m_allocationVars.empty())

src/OpenColorIO/ColorSpaceSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class ColorSpaceSet::Impl
180180

181181
void remove(const char * csName)
182182
{
183+
if (!csName || !*csName) return;
183184
const std::string name = StringUtils::Lower(csName);
184185
if (name.empty()) return;
185186

src/OpenColorIO/Config.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4337,7 +4337,7 @@ int Config::getNumDisplaysAll() const noexcept
43374337

43384338
const char * Config::getDisplayAll(int index) const noexcept
43394339
{
4340-
if (index >= 0 || index < static_cast<int>(getImpl()->m_displays.size()))
4340+
if (index >= 0 && index < static_cast<int>(getImpl()->m_displays.size()))
43414341
{
43424342
return getImpl()->m_displays[index].first.c_str();
43434343
}
@@ -4365,7 +4365,7 @@ int Config::getDisplayAllByName(const char * name) const noexcept
43654365

43664366
bool Config::isDisplayTemporary(int index) const noexcept
43674367
{
4368-
if (index >= 0 || index < static_cast<int>(getImpl()->m_displays.size()))
4368+
if (index >= 0 && index < static_cast<int>(getImpl()->m_displays.size()))
43694369
{
43704370
return getImpl()->m_displays[index].second.m_temporary;
43714371
}
@@ -4375,7 +4375,7 @@ bool Config::isDisplayTemporary(int index) const noexcept
43754375

43764376
void Config::setDisplayTemporary(int index, bool isTemporary) noexcept
43774377
{
4378-
if (index >= 0 || index < static_cast<int>(getImpl()->m_displays.size()))
4378+
if (index >= 0 && index < static_cast<int>(getImpl()->m_displays.size()))
43794379
{
43804380
getImpl()->m_displays[index].second.m_temporary = isTemporary;
43814381

@@ -4410,7 +4410,7 @@ const char * Config::getView(ViewType type, const char * display, int index) con
44104410
{
44114411
if (!display || !*display)
44124412
{
4413-
if (index >= 0 || index < static_cast<int>(getImpl()->m_sharedViews.size()))
4413+
if (index >= 0 && index < static_cast<int>(getImpl()->m_sharedViews.size()))
44144414
{
44154415
return getImpl()->m_sharedViews[index].m_name.c_str();
44164416
}
@@ -4449,11 +4449,19 @@ const char * Config::getView(ViewType type, const char * display, int index) con
44494449

44504450
void Config::getDefaultLumaCoefs(double * c3) const
44514451
{
4452+
if (!c3)
4453+
{
4454+
throw Exception("getDefaultLumaCoefs: c3 must not be null.");
4455+
}
44524456
memcpy(c3, &getImpl()->m_defaultLumaCoefs[0], 3*sizeof(double));
44534457
}
44544458

44554459
void Config::setDefaultLumaCoefs(const double * c3)
44564460
{
4461+
if (!c3)
4462+
{
4463+
throw Exception("setDefaultLumaCoefs: c3 must not be null.");
4464+
}
44574465
memcpy(&getImpl()->m_defaultLumaCoefs[0], c3, 3*sizeof(double));
44584466

44594467
AutoMutex lock(getImpl()->m_cacheidMutex);

src/OpenColorIO/ContextVariableUtils.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ void LoadEnvironment(EnvMap & map, bool update)
101101

102102
const std::string env_str = (char*)*env;
103103
#endif
104-
const int pos = static_cast<int>(env_str.find_first_of('='));
104+
const auto pos = env_str.find_first_of('=');
105+
106+
if (pos == std::string::npos) continue;
105107

106108
const std::string name = env_str.substr(0, pos);
107-
const std::string value = env_str.substr(pos+1, env_str.length());
109+
const std::string value = env_str.substr(pos+1);
108110

109111
if (update)
110112
{
@@ -122,8 +124,12 @@ void LoadEnvironment(EnvMap & map, bool update)
122124
}
123125
}
124126

125-
std::string ResolveContextVariables(const std::string & str, const EnvMap & map, UsedEnvs & used)
127+
static std::string ResolveContextVariablesImpl(const std::string & str, const EnvMap & map,
128+
UsedEnvs & used, int depth)
126129
{
130+
// Guard against infinite recursion from cyclic variable references.
131+
if (depth > 32) return str;
132+
127133
// Early exit if no reserved tokens are found.
128134
if (!ContainsContextVariables(str))
129135
{
@@ -159,12 +165,17 @@ std::string ResolveContextVariables(const std::string & str, const EnvMap & map,
159165
// recursively call till string doesn't expand anymore
160166
if(newstr != orig)
161167
{
162-
return ResolveContextVariables(newstr, map, used);
168+
return ResolveContextVariablesImpl(newstr, map, used, depth + 1);
163169
}
164170

165171
return orig;
166172
}
167173

174+
std::string ResolveContextVariables(const std::string & str, const EnvMap & map, UsedEnvs & used)
175+
{
176+
return ResolveContextVariablesImpl(str, map, used, 0);
177+
}
178+
168179
bool CollectContextVariables(const Config & config,
169180
const Context & context,
170181
ConstTransformRcPtr transform,

src/OpenColorIO/CustomKeys.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,24 @@ class CustomKeysContainer
6161

6262
bool hasKey(const char * key)
6363
{
64-
std::string s = key;
65-
return m_customKeys.count(s) > 0;
64+
if (!key || !*key) return false;
65+
return m_customKeys.count(key) > 0;
6666
}
6767

6868
const char * getValueForKey(const char * key)
6969
{
70-
// NB: Will throw if the map doesn't have the key.
71-
return m_customKeys[key].c_str();
70+
if (!key || !*key)
71+
{
72+
throw Exception("Key has to be a non-empty string.");
73+
}
74+
auto it = m_customKeys.find(key);
75+
if (it == m_customKeys.end())
76+
{
77+
std::ostringstream oss;
78+
oss << "Key '" << key << "' not found.";
79+
throw Exception(oss.str().c_str());
80+
}
81+
return it->second.c_str();
7282
}
7383

7484
private:

src/OpenColorIO/Display.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void AddView(ViewVec & views, const char * name, const char * viewTransform,
5252
const char * displayColorSpace, const char * looks,
5353
const char * rule, const char * description)
5454
{
55-
if (0 == Platform::Strcasecmp(displayColorSpace, OCIO_VIEW_USE_DISPLAY_NAME))
55+
if (displayColorSpace && 0 == Platform::Strcasecmp(displayColorSpace, OCIO_VIEW_USE_DISPLAY_NAME))
5656
{
5757
displayColorSpace = OCIO_VIEW_USE_DISPLAY_NAME;
5858
}

src/OpenColorIO/Display.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct View
3737
const char * looks,
3838
const char * rule,
3939
const char * description)
40-
: m_name(name)
40+
: m_name(name ? name : "")
4141
, m_viewTransform(viewTransform ? viewTransform : "")
4242
, m_colorspace(colorspace ? colorspace : "")
4343
, m_looks(looks ? looks : "")

0 commit comments

Comments
 (0)