Skip to content

Commit

Permalink
Fix the NPR problem in the Codec::InstallReferences() methods. (#2253)
Browse files Browse the repository at this point in the history
  • Loading branch information
domchen committed Apr 17, 2024
1 parent d80cc3c commit b2fcd22
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions resources/fuzz/poc6.pag
Git LFS file not shown
15 changes: 10 additions & 5 deletions src/codec/Codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ uint16_t Codec::MaxSupportedTagLevel() {
return static_cast<uint16_t>(TagCode::Count) - 1;
}

template <typename T>
ID GetReferenceID(T* item) {
return item ? item->id : 0;
}

void Codec::InstallReferences(Layer* layer) {
std::unordered_map<ID, MaskData*> maskMap;
for (auto mask : layer->masks) {
Expand All @@ -56,7 +61,7 @@ void Codec::InstallReferences(Layer* layer) {
for (auto effect : layer->effects) {
if (!effect->maskReferences.empty()) {
for (auto i = static_cast<int>(effect->maskReferences.size() - 1); i >= 0; i--) {
auto id = effect->maskReferences[i]->id;
auto id = GetReferenceID(effect->maskReferences[i]);
delete effect->maskReferences[i];
auto result = maskMap.find(id);
if (result != maskMap.end()) {
Expand All @@ -70,7 +75,7 @@ void Codec::InstallReferences(Layer* layer) {
if (layer->type() == LayerType::Text) {
auto pathOption = static_cast<TextLayer*>(layer)->pathOption;
if (pathOption && pathOption->path) {
auto id = pathOption->path->id;
auto id = GetReferenceID(pathOption->path);
delete pathOption->path;
pathOption->path = nullptr;
auto result = maskMap.find(id);
Expand All @@ -90,7 +95,7 @@ void Codec::InstallReferences(const std::vector<Layer*>& layers) {
int index = 0;
for (auto layer : layers) {
if (layer->parent) {
auto id = layer->parent->id;
auto id = GetReferenceID(layer->parent);
delete layer->parent;
layer->parent = nullptr;
auto result = layerMap.find(id);
Expand All @@ -104,7 +109,7 @@ void Codec::InstallReferences(const std::vector<Layer*>& layers) {
for (auto effect : layer->effects) {
auto displacementMap = static_cast<DisplacementMapEffect*>(effect);
if (effect->type() == EffectType::DisplacementMap && displacementMap->displacementMapLayer) {
auto id = displacementMap->displacementMapLayer->id;
auto id = GetReferenceID(displacementMap->displacementMapLayer);
delete displacementMap->displacementMapLayer;
displacementMap->displacementMapLayer = nullptr;
auto result = layerMap.find(id);
Expand All @@ -129,7 +134,7 @@ void Codec::InstallReferences(const std::vector<Composition*>& compositions) {
if (layer->type() == LayerType::PreCompose &&
static_cast<PreComposeLayer*>(layer)->composition) {
auto preComposeLayer = static_cast<PreComposeLayer*>(layer);
auto id = preComposeLayer->composition->id;
auto id = GetReferenceID(preComposeLayer->composition);
delete preComposeLayer->composition;
preComposeLayer->composition = nullptr;
auto result = compositionMap.find(id);
Expand Down

0 comments on commit b2fcd22

Please sign in to comment.