Skip to content

Commit 2b4bf65

Browse files
committed
Protect filter() against damaged projects
1 parent 5e90b39 commit 2b4bf65

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

src/classes/query.py

+38-30
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
"""
1+
"""
22
@file
33
@brief This file can easily query Clips, Files, and other project data
44
@author Jonathan Thomas <[email protected]>
5-
5+
66
@section LICENSE
7-
7+
88
Copyright (c) 2008-2018 OpenShot Studios, LLC
99
(http://www.openshotstudios.com). This file is part of
1010
OpenShot Video Editor (http://www.openshot.org), an open-source project
1111
dedicated to delivering high quality video editing and animation solutions
1212
to the world.
13-
13+
1414
OpenShot Video Editor is free software: you can redistribute it and/or modify
1515
it under the terms of the GNU General Public License as published by
1616
the Free Software Foundation, either version 3 of the License, or
1717
(at your option) any later version.
18-
18+
1919
OpenShot Video Editor is distributed in the hope that it will be useful,
2020
but WITHOUT ANY WARRANTY; without even the implied warranty of
2121
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2222
GNU General Public License for more details.
23-
23+
2424
You should have received a copy of the GNU General Public License
2525
along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
2626
"""
@@ -32,7 +32,6 @@
3232
from classes.app import get_app
3333

3434

35-
3635
# Get project data reference
3736
app = get_app()
3837
project = app.project
@@ -97,33 +96,42 @@ def filter(OBJECT_TYPE, **kwargs):
9796

9897
# Get a list of all objects of this type
9998
parent = project.get(OBJECT_TYPE.object_key)
99+
100+
if not parent:
101+
return []
102+
100103
matching_objects = []
101104

102105
# Loop through all children objects
103-
if parent:
104-
for child in parent:
105-
106-
# Loop through all kwargs (and look for matches)
107-
match = True
108-
for key, value in kwargs.items():
109-
# Equals
110-
if key in child and not child[key] == value:
106+
for child in parent:
107+
108+
# Protect against non-iterable/subscriptables
109+
if not child:
110+
continue
111+
112+
# Loop through all kwargs (and look for matches)
113+
match = True
114+
for key, value in kwargs.items():
115+
116+
# Equals
117+
if key in child and not child[key] == value:
118+
match = False
119+
break
120+
121+
# Intersection Position
122+
if key == "intersect":
123+
if (child.get("position", 0) > value or
124+
child.get("position", 0) + (child.get("end", 0) - child.get("start", 0)) < value):
111125
match = False
112-
break
113-
# Intersection Position
114-
elif key == "intersect":
115-
if child.get("position", 0) > value or \
116-
child.get("position", 0) + (child.get("end", 0) - child.get("start", 0)) < value:
117-
match = False
118-
119-
# Add matched record
120-
if match:
121-
object = OBJECT_TYPE()
122-
object.id = child["id"]
123-
object.key = [OBJECT_TYPE.object_name, {"id": object.id}]
124-
object.data = copy.deepcopy(child) # copy of object
125-
object.type = "update"
126-
matching_objects.append(object)
126+
127+
# Add matched record
128+
if match:
129+
object = OBJECT_TYPE()
130+
object.id = child["id"]
131+
object.key = [OBJECT_TYPE.object_name, {"id": object.id}]
132+
object.data = copy.deepcopy(child) # copy of object
133+
object.type = "update"
134+
matching_objects.append(object)
127135

128136
# Return matching objects
129137
return matching_objects

0 commit comments

Comments
 (0)