Skip to content

Commit d2314ed

Browse files
authored
Merge pull request #1537 from volatilityfoundation/issues/improve-jsonschema-speed
Issues/improve jsonschema speed
2 parents 51726cd + 749a0f9 commit d2314ed

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

pyproject.toml

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
[project]
22
name = "volatility3"
33
description = "Memory forensics framework"
4-
keywords = ["volatility", "memory", "forensics", "framework", "windows", "linux", "volshell"]
4+
keywords = [
5+
"volatility",
6+
"memory",
7+
"forensics",
8+
"framework",
9+
"windows",
10+
"linux",
11+
"volshell",
12+
]
513
readme = "README.md"
614
authors = [
715
{ name = "Volatility Foundation", email = "volatility@volatilityfoundation.org" },
@@ -10,9 +18,7 @@ requires-python = ">=3.8.0"
1018
license = { text = "VSL" }
1119
dynamic = ["version"]
1220

13-
dependencies = [
14-
"pefile>=2024.8.26",
15-
]
21+
dependencies = ["pefile>=2024.8.26"]
1622

1723
[project.optional-dependencies]
1824
full = [
@@ -26,10 +32,7 @@ full = [
2632
"pillow>=10.0.0,<11.0.0",
2733
]
2834

29-
cloud = [
30-
"gcsfs>=2024.10.0",
31-
"s3fs>=2024.10.0",
32-
]
35+
cloud = ["gcsfs>=2024.10.0", "s3fs>=2024.10.0"]
3336

3437
dev = [
3538
"volatility3[full,cloud]",
@@ -79,16 +82,16 @@ target-version = "py38"
7982

8083
[tool.ruff.lint]
8184
select = [
82-
"F", # pyflakes
83-
"E", # pycodestyle errors
84-
"W", # pycodestyle warnings
85-
"G", # flake8-logging-format
86-
"PIE", # flake8-pie
87-
"UP", # pyupgrade
85+
"F", # pyflakes
86+
"E", # pycodestyle errors
87+
"W", # pycodestyle warnings
88+
"G", # flake8-logging-format
89+
"PIE", # flake8-pie
90+
"UP", # pyupgrade
8891
]
8992

9093
ignore = [
91-
"E501", # ignore due to conflict with formatter
94+
"E501", # ignore due to conflict with formatter
9295
]
9396

9497
[build-system]

volatility3/schemas/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
cached_validation_filepath = os.path.join(constants.CACHE_PATH, "valid_isf.hashcache")
1616

17+
validators = {}
18+
1719

1820
def load_cached_validations() -> Set[str]:
1921
"""Loads up the list of successfully cached json objects, so we don't need
@@ -93,14 +95,21 @@ def valid(
9395
return True
9496
try:
9597
import jsonschema
98+
99+
schema_key = json.dumps(schema, sort_keys=True)
100+
if schema_key not in validators:
101+
validator_class = jsonschema.validators.validator_for(schema)
102+
validator_class.check_schema(schema)
103+
validator = validator_class(schema)
104+
validators[schema_key] = validator
96105
except ImportError:
97106
vollog.info("Dependency for validation unavailable: jsonschema")
98107
vollog.debug("All validations will report success, even with malformed input")
99108
return True
100109

101110
try:
102111
vollog.debug("Validating JSON against schema...")
103-
jsonschema.validate(input, schema)
112+
validators[schema_key].validate(input)
104113
cached_validations.add(input_hash)
105114
vollog.debug("JSON validated against schema (result cached)")
106115
except jsonschema.exceptions.SchemaError:

0 commit comments

Comments
 (0)