66import json
77import logging
88import os
9- from typing import Any , Dict , Optional , Set
10-
9+ import re
10+ from typing import Any , Dict , Optional , Set , Tuple
1111from volatility3 .framework import constants
1212
1313vollog = logging .getLogger (__name__ )
@@ -77,6 +77,17 @@ def valid(
7777 input : Dict [str , Any ], schema : Dict [str , Any ], use_cache : bool = True
7878) -> bool :
7979 """Validates a json schema."""
80+ producer = input .get ("metadata" , {}).get ("producer" , {})
81+ if producer and producer .get ("name" ) == "dwarf2json" :
82+ dwarf2json_version = parse_producer_version (producer .get ("version" , "" ))
83+ # No warnings if version couldn't be parsed, as it's not our role here
84+ # to validate the schema.
85+ if dwarf2json_version :
86+ if dwarf2json_check_rust_type_confusion (input , dwarf2json_version ):
87+ vollog .warning (
88+ "This ISF was generated by dwarf2json < 0.9.0, which is known to produce inaccurate results (see dwarf2json GitHub issue #63)."
89+ )
90+
8091 input_hash = create_json_hash (input , schema )
8192 if input_hash in cached_validations and use_cache :
8293 return True
@@ -98,3 +109,42 @@ def valid(
98109
99110 record_cached_validations (cached_validations )
100111 return True
112+
113+
114+ def parse_producer_version (version_string : str ) -> Optional [Tuple [int ]]:
115+ """Parses a producer version and returns a tuple of identifiers.
116+
117+ Args:
118+ version_string: string containing dot-separated integers,
119+ expected to follow the Volatility3 versioning schema
120+
121+ Returns:
122+ A tuple containing each version identifier
123+ """
124+ identifiers = re .search ("^(\\ d+)[.](\\ d+)[.](\\ d+)$" , version_string )
125+ if not identifiers :
126+ return None
127+
128+ return tuple (int (d ) for d in identifiers .groups ())
129+
130+
131+ # dwarf2json sanity checks #
132+ def dwarf2json_check_rust_type_confusion (
133+ input : Dict [str , Any ], dwarf2json_version : Tuple [int ]
134+ ) -> bool :
135+ """dwarf2json sanity check for Rust and C types confusion:
136+ - dwarf2json #63
137+ - volatility3 #1305
138+
139+ Args:
140+ dwarf2json_version: a tuple containing each version identifier
141+
142+ Returns:
143+ True if the issue was detected
144+ """
145+
146+ return "rust_helper_BUG" in input .get ("symbols" , {}) and dwarf2json_version < (
147+ 0 ,
148+ 9 ,
149+ 0 ,
150+ )
0 commit comments