Skip to content

Commit

Permalink
Merge pull request #1537 from volatilityfoundation/issues/improve-jso…
Browse files Browse the repository at this point in the history
…nschema-speed

Issues/improve jsonschema speed
  • Loading branch information
ikelos authored Jan 20, 2025
2 parents 51726cd + 749a0f9 commit d2314ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
33 changes: 18 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]" },
Expand All @@ -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 = [
Expand All @@ -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]",
Expand Down Expand Up @@ -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]
Expand Down
11 changes: 10 additions & 1 deletion volatility3/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

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
Expand Down Expand Up @@ -93,14 +95,21 @@ 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")
return True

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:
Expand Down

0 comments on commit d2314ed

Please sign in to comment.