Skip to content

Commit

Permalink
fix Seed deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDavid committed Jul 16, 2024
1 parent 6b396df commit d337c63
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions tritondse/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,20 @@ def from_bytes(raw_seed: bytes, status: SeedStatus = SeedStatus.NEW) -> 'Seed':
:rtype: Seed
"""
try:
data = json.loads(raw_seed)

if not isinstance(data, dict): # it might happen that files contains only digit which is a valid JSON
return Seed(raw_seed, status)

if 'files' in data and 'argv' in data:
return Seed(CompositeData.from_dict(data), status)
else: # Else still consider file as raw bytes
if raw_seed.startswith(b"{"):
data = json.loads(raw_seed)

# Check that it contains the expected keys
if 'files' in data and 'argv' in data:
return Seed(CompositeData.from_dict(data), status)
else: # Else still consider file as raw bytes
return Seed(raw_seed, status)
else:
return Seed(raw_seed, status)
except (json.JSONDecodeError, UnicodeDecodeError):
return Seed(raw_seed, status)
except ValueError: # JSON parser might raise value error
return Seed(raw_seed, status)

@staticmethod
def from_file(path: PathLike, status: SeedStatus = SeedStatus.NEW) -> 'Seed':
Expand Down

0 comments on commit d337c63

Please sign in to comment.