Skip to content

Commit

Permalink
fixed potential crash - cf #1389
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlf committed Jun 15, 2020
1 parent bd96f67 commit 1baf7c6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 28 deletions.
10 changes: 9 additions & 1 deletion src/bifs/field_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@


#include <gpac/internal/bifs_dev.h>
#include <gpac/scene_manager.h>
#include "quant.h"
#include "script.h"

Expand Down Expand Up @@ -721,9 +722,16 @@ GF_Node *gf_bifs_dec_node(GF_BifsDecoder * codec, GF_BitStream *bs, u32 NDT_Tag)
/*NULL node is encoded as USE with ID = all bits to 1*/
if (nodeID == (u32) (1<<codec->info->config.NodeIDBits))
return NULL;
//find node and return it
//find node
new_node = gf_sg_find_node(codec->current_graph, nodeID);

//check node is allowed for the given NDT
if (new_node && !gf_node_in_table(new_node, NDT_Tag)) {
GF_LOG(GF_LOG_ERROR, GF_LOG_CODING, ("[BIFS] Node %s not allowed as field/child of NDT type %d\n", gf_node_get_class_name(new_node), NDT_Tag));
codec->LastError = GF_SG_UNKNOWN_NODE;
return NULL;
}

if (!new_node) {
codec->LastError = GF_SG_UNKNOWN_NODE;
} else {
Expand Down
54 changes: 27 additions & 27 deletions src/scenegraph/base_scenegraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ void gf_sg_reset(GF_SceneGraph *sg)
reg_node = sg->id_node;
while (reg_node) {
Bool ignore = 0;
GF_ParentList *nlist;
GF_Node *node = reg_node->node;
if (!node
#ifndef GPAC_DISABLE_VRML
Expand All @@ -396,43 +397,42 @@ void gf_sg_reset(GF_SceneGraph *sg)

/*first replace all instances in parents by NULL WITHOUT UNREGISTERING (to avoid destroying the node).
This will take care of nodes referencing themselves*/
{
GF_ParentList *nlist = node->sgprivate->parents;
nlist = node->sgprivate->parents;
#ifndef GPAC_DISABLE_SVG
type = (node->sgprivate->tag>GF_NODE_RANGE_LAST_VRML) ? 1 : 0;
type = (node->sgprivate->tag>GF_NODE_RANGE_LAST_VRML) ? 1 : 0;
#endif
while (nlist) {
GF_ParentList *next = nlist->next;
while (nlist) {
GF_ParentList *next = nlist->next;
#if 0
/*parent is a DEF'ed node, try to clean-up properly?*/
if ((nlist->node!=node) && SG_SearchForNode(sg, nlist->node) != NULL) {
ignore = 1;
break;
}
/*parent is a DEF'ed node, try to clean-up properly?*/
if ((nlist->node!=node) && SG_SearchForNode(sg, nlist->node) != NULL) {
ignore = 1;
break;
}
#endif

#ifndef GPAC_DISABLE_SVG
if (type) {
ReplaceIRINode(nlist->node, node, NULL);
} else
if (type) {
ReplaceIRINode(nlist->node, node, NULL);
} else
#endif
ReplaceDEFNode(nlist->node, reg_node->node, NULL, 0);
ReplaceDEFNode(nlist->node, reg_node->node, NULL, 0);

/*direct cyclic reference to ourselves, make sure we update the parentList to the next entry before freeing it
since the next parent node could be reg_node again (reg_node->reg_node)*/
if (nlist->node==node) {
node->sgprivate->parents = next;
}
gf_free(nlist);
nlist = next;
/*direct cyclic reference to ourselves, make sure we update the parentList to the next entry before freeing it
since the next parent node could be reg_node again (reg_node->reg_node)*/
if (nlist->node==node) {
node->sgprivate->parents = next;
}
if (ignore) {
node->sgprivate->parents = nlist;
continue;
}

node->sgprivate->parents = NULL;
gf_free(nlist);
nlist = next;
}
if (ignore) {
node->sgprivate->parents = nlist;
continue;
}

node->sgprivate->parents = NULL;

//sg->node_registry[i-1] = NULL;
count = get_num_id_nodes(sg);
node->sgprivate->num_instances = 1;
Expand Down

0 comments on commit 1baf7c6

Please sign in to comment.