From 5820fa0845761851f4829ccba45b2afc31b51c57 Mon Sep 17 00:00:00 2001 From: Greg Back Date: Wed, 14 Mar 2018 10:06:03 -0500 Subject: [PATCH] GH-138: ignore invalid JSON files. --- stix2/datastore/filesystem.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stix2/datastore/filesystem.py b/stix2/datastore/filesystem.py index 26d0c58..a00c6e1 100644 --- a/stix2/datastore/filesystem.py +++ b/stix2/datastore/filesystem.py @@ -303,7 +303,11 @@ class FileSystemSource(DataSource): for file_ in files: if not id_ or id_ == file_.split(".")[0]: # have to load into memory regardless to evaluate other filters - stix_obj = json.load(open(os.path.join(root, file_))) + try: + stix_obj = json.load(open(os.path.join(root, file_))) + except UnicodeDecodeError: # likely not a JSON file + # TODO: log a warning somehow? (os.path.abspath(file_))) + continue if stix_obj.get('type', '') == 'bundle': stix_obj = stix_obj['objects'][0] # check against other filters, add if match