Skip to content

Commit

Permalink
[Crash] Fix crash with invalid patterns (e.g. unclosed parenthesis)
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-mercs committed Aug 20, 2020
1 parent ed87c5a commit d687db9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions nuke/DeepOpenEXRId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static std::string hashCString (const char *p)
}

template<>
DeepOpenEXRId::ExrIdDataPtr DeepOpenEXRId::ExrIdDataCacheType::build(const std::string &hash, const void * build_data)
DeepOpenEXRId::ExrIdDataPtr DeepOpenEXRId::ExrIdDataCacheType::build(const std::string &hash, const void * build_data, DeepOpenEXRId * notifier)
{
log ("Loading EXRId data ...");

Expand Down Expand Up @@ -332,14 +332,14 @@ OpenEXRId::shared_ptr<DeepOpenEXRId::ExrIdData> DeepOpenEXRId::_getExrIdData ()
hash = MD5DigestToString (digest);
}

return ExrIdDataCache.get (hash, static_cast<const void*>(&metadata));
return ExrIdDataCache.get (hash, static_cast<const void*>(&metadata), this);
}




template<>
DeepOpenEXRId::NameAutomatonPtr DeepOpenEXRId::NameAutomatonCacheType::build(const std::string &hash, const void * build_data)
DeepOpenEXRId::NameAutomatonPtr DeepOpenEXRId::NameAutomatonCacheType::build(const std::string &hash, const void * build_data, DeepOpenEXRId * notifier)
{
log ("Compiling name automaton ...");

Expand All @@ -358,14 +358,14 @@ DeepOpenEXRId::NameAutomatonPtr DeepOpenEXRId::NameAutomatonCacheType::build(con
std::string err;
if (set->RegEx.Add (removeNeg (*pattern), &err) < 0)
{
((DeepOpenEXRId*)this)->error ("Bad regular expression '%s': %s", pattern->c_str (), err.c_str ());
notifier->error ("Bad regular expression '%s': %s", pattern->c_str (), err.c_str ());
return OpenEXRId::make_shared<NameAutomaton> ();
}
}

if (!set->RegEx.Compile ())
{
((DeepOpenEXRId*)this)->error ("Automaton compilation error");
notifier->error ("Automaton compilation error");
return OpenEXRId::make_shared<NameAutomaton> ();
}

Expand All @@ -385,7 +385,7 @@ DeepOpenEXRId::NameAutomatonPtr DeepOpenEXRId::_getNamesAutomaton ()
// Note: we could keep a hash of _patterns and invalidate it with knob_changed
// but _patterns is not supposed to grow incontrollably, so there negigeable gain here
std::string hash = hashCString (_patterns);
return NameAutomatonCache.get (hash, static_cast<const void*>(_patterns));
return NameAutomatonCache.get (hash, static_cast<const void*>(_patterns), this);
}

bool DeepOpenEXRId::NameAutomaton::match (const std::string &name, std::vector<int> &tmp) const
Expand All @@ -406,7 +406,7 @@ bool DeepOpenEXRId::NameAutomaton::match (const std::string &name, std::vector<i
}

template<>
DeepOpenEXRId::LPEAutomatonPtr DeepOpenEXRId::LPEAutomatonCacheType::build(const std::string &hash, const void * build_data)
DeepOpenEXRId::LPEAutomatonPtr DeepOpenEXRId::LPEAutomatonCacheType::build(const std::string &hash, const void * build_data, DeepOpenEXRId * notifier)
{
log ("Compiling lpe automaton ...");

Expand All @@ -430,7 +430,7 @@ DeepOpenEXRId::LPEAutomatonPtr DeepOpenEXRId::LPEAutomatonCacheType::build(const
OSL::LPexp *e = parser.parse (removeNeg (*pattern));
if (parser.error ())
{
((DeepOpenEXRId*)this)->error ("Bad light path expression '%s': %s", pattern->c_str (), parser.getErrorMsg ());
notifier->error ("Bad light path expression '%s': %s", pattern->c_str (), parser.getErrorMsg ());
return OpenEXRId::make_shared<LPEAutomaton> ();
}
else
Expand Down Expand Up @@ -458,7 +458,7 @@ DeepOpenEXRId::LPEAutomatonPtr DeepOpenEXRId::_getLPEAutomaton ()
// Note: we could keep a hash of _LPEs and invalidate it with knob_changed
// but _LPEs is not supposed to grow incontrollably, so there negigeable gain here
std::string hash = hashCString (_LPEs);
return LPEAutomatonCache.get (hash, static_cast<const void*>(_LPEs));
return LPEAutomatonCache.get (hash, static_cast<const void*>(_LPEs), this);
}

bool DeepOpenEXRId::LPEAutomaton::match (const LightPath &lightpath) const
Expand Down Expand Up @@ -493,7 +493,7 @@ bool DeepOpenEXRId::LPEAutomaton::match (const LightPath &lightpath) const
}

template<>
DeepOpenEXRId::StatePtr DeepOpenEXRId::StateCacheType::build(const std::string &hash, const void * build_data)
DeepOpenEXRId::StatePtr DeepOpenEXRId::StateCacheType::build(const std::string &hash, const void * build_data, DeepOpenEXRId * notifier)
{
log ("Building exrid active state ...");

Expand Down Expand Up @@ -548,7 +548,7 @@ DeepOpenEXRId::StatePtr DeepOpenEXRId::_getState (
std::string hash = MD5DigestToString (digest);

State::BuildData state_data = {exrid, namesregex, lperegex};
return StateCache.get (hash, static_cast<const void*>(&state_data));
return StateCache.get (hash, static_cast<const void*>(&state_data), this);
}

bool DeepOpenEXRId::doDeepEngine(DD::Image::Box box, const ChannelSet& channels, DeepOutputPlane& plane)
Expand Down
6 changes: 3 additions & 3 deletions nuke/DeepOpenEXRId.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,18 @@ class DeepOpenEXRId : public DD::Image::DeepFilterOp
H Hash;
T Value;

T get (const H &hash, const void * build_data)
T get (const H &hash, const void * build_data, DeepOpenEXRId * notifier)
{
OpenEXRId::lock_guard<OpenEXRId::mutex> guard (Mutex);
if (hash != Hash)
{
Value = build (hash, build_data);
Value = build (hash, build_data, notifier);
Hash = hash;
}
return Value;
}

T build(const H &hash, const void * build_data);
T build(const H &hash, const void * build_data, DeepOpenEXRId * notifier);
};

// This is the metadata we grabd from the input exrid
Expand Down
2 changes: 1 addition & 1 deletion openexrid/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
namespace openexrid
{

std::string Version = "1.0-beta.24";
std::string Version = "1.0-beta.25";

}

0 comments on commit d687db9

Please sign in to comment.