Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues/improve jsonschema speed #1537

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion volatility3/framework/plugins/isfinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _generator(self):
if filter_item in isf_file:
filtered_list.append(isf_file)

if find_spec("jsonschema") and self.config["validate"]:
if find_spec("fastjsonschema") and self.config["validate"]:

def check_valid(data):
return "True" if schemas.validate(data, True) else "False"
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
Loading