Merge pull request #1537 from volatilityfoundation/issues/improve-jsonschema-speed

Issues/improve jsonschema speed
This commit is contained in:
ikelos
2025-01-20 08:26:32 +00:00
committed by GitHub
2 changed files with 28 additions and 16 deletions
+18 -15
View File
@@ -1,7 +1,15 @@
[project]
name = "volatility3"
description = "Memory forensics framework"
keywords = ["volatility", "memory", "forensics", "framework", "windows", "linux", "volshell"]
keywords = [
"volatility",
"memory",
"forensics",
"framework",
"windows",
"linux",
"volshell",
]
readme = "README.md"
authors = [
{ name = "Volatility Foundation", email = "volatility@volatilityfoundation.org" },
@@ -10,9 +18,7 @@ requires-python = ">=3.8.0"
license = { text = "VSL" }
dynamic = ["version"]
dependencies = [
"pefile>=2024.8.26",
]
dependencies = ["pefile>=2024.8.26"]
[project.optional-dependencies]
full = [
@@ -26,10 +32,7 @@ full = [
"pillow>=10.0.0,<11.0.0",
]
cloud = [
"gcsfs>=2024.10.0",
"s3fs>=2024.10.0",
]
cloud = ["gcsfs>=2024.10.0", "s3fs>=2024.10.0"]
dev = [
"volatility3[full,cloud]",
@@ -79,16 +82,16 @@ target-version = "py38"
[tool.ruff.lint]
select = [
"F", # pyflakes
"E", # pycodestyle errors
"W", # pycodestyle warnings
"G", # flake8-logging-format
"PIE", # flake8-pie
"UP", # pyupgrade
"F", # pyflakes
"E", # pycodestyle errors
"W", # pycodestyle warnings
"G", # flake8-logging-format
"PIE", # flake8-pie
"UP", # pyupgrade
]
ignore = [
"E501", # ignore due to conflict with formatter
"E501", # ignore due to conflict with formatter
]
[build-system]
+10 -1
View File
@@ -14,6 +14,8 @@ vollog = logging.getLogger(__name__)
cached_validation_filepath = os.path.join(constants.CACHE_PATH, "valid_isf.hashcache")
validators = {}
def load_cached_validations() -> Set[str]:
"""Loads up the list of successfully cached json objects, so we don't need
@@ -93,6 +95,13 @@ def valid(
return True
try:
import jsonschema
schema_key = json.dumps(schema, sort_keys=True)
if schema_key not in validators:
validator_class = jsonschema.validators.validator_for(schema)
validator_class.check_schema(schema)
validator = validator_class(schema)
validators[schema_key] = validator
except ImportError:
vollog.info("Dependency for validation unavailable: jsonschema")
vollog.debug("All validations will report success, even with malformed input")
@@ -100,7 +109,7 @@ def valid(
try:
vollog.debug("Validating JSON against schema...")
jsonschema.validate(input, schema)
validators[schema_key].validate(input)
cached_validations.add(input_hash)
vollog.debug("JSON validated against schema (result cached)")
except jsonschema.exceptions.SchemaError: